You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@jdalton/simple-xml-to-json

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jdalton/simple-xml-to-json - npm Package Compare versions

Comparing version

to
1.2.7

948

lib/simpleXmlToJson.js

@@ -1,5 +0,5 @@

'use strict'
'use strict';
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

@@ -10,31 +10,44 @@

value: ''
})
});
function createLexer$1(xmlAsString) {
const { length } = xmlAsString
const scopingTagName = []
let currentToken = null
let pos = 0
function createLexer$1(xmlAsString, { knownAttrib, knownElement } = {}) {
const { length } = xmlAsString;
const scoping = [];
let currScope = 0;
let currToken = EOF_TOKEN;
let currTokenType = 0;
let peekedPos = 0;
let peekedTagName = '';
let peekedTokenType = 0;
let pos = 0;
const getPos = () => pos
const peek = () => xmlAsString.charCodeAt(pos)
const hasNextPos = () => pos < length
const hasNextToken = () => currentToken !== EOF_TOKEN && pos < length
const getPos = () => pos;
const getScope = () => currScope;
const peek = () => xmlAsString.charCodeAt(pos);
const hasNext = () => pos < length;
const replaceQuotes = ($str) => {
let output = ''
let fromIndex = 0
let index = 0
while ((index = $str.indexOf("'", fromIndex)) !== -1) {
output = output + $str.slice(fromIndex, index) + '"'
fromIndex = index + 1
const readAlphaNumericAndSpecialChars = () => {
const start = pos;
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[^>=<]/u.test(xmlAsString[pos])
if (
code !== 60 &&
code !== 61 &&
code !== 62
) {
pos += 1;
continue
}
break
}
return fromIndex ? output + $str.slice(fromIndex) : $str
}
const str = xmlAsString.slice(start, pos);
return replaceQuotes(str)
};
const readBracketsAsBitmask = () => {
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
const code = (xmlAsString.charCodeAt(pos));
if (code === 60) {
pos += 1
pos += 1;
if (

@@ -44,3 +57,3 @@ (pos < length) &&

) {
pos += 1
pos += 1;
return 3

@@ -55,3 +68,3 @@ }

// its a comment
pos += 3
pos += 3;
return 16

@@ -62,3 +75,3 @@ }

if (code === 47) {
pos += 1
pos += 1;
if (

@@ -68,3 +81,3 @@ (pos < length) &&

) {
pos += 1
pos += 1;
return 5

@@ -74,6 +87,6 @@ }

} else if (code === 61) {
pos += 1
pos += 1;
return 8
} else if (code === 62) {
pos += 1
pos += 1;
return 4

@@ -83,53 +96,8 @@ }

return 0
}
};
const readAlphaNumericCharsAndBrackets = () => {
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if (code === 60) {
pos += 1
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 47
) {
pos += 1
return '</'
}
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 33 &&
xmlAsString.charCodeAt(pos + 1) === 45 &&
xmlAsString.charCodeAt(pos + 2) === 45
) {
// its a comment
pos += 3
return '<!--'
}
return '<'
}
if (code === 47) {
pos += 1
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 62
) {
pos += 1
return '/>'
}
return '/'
} else if (code === 61) {
pos += 1
return '='
} else if (code === 62) {
pos += 1
return '>'
}
}
return readAlphaNumericChars()
}
const readAlphaNumericChars = () => {
let start = pos
const readTagName = () => {
let start = pos;
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
const code = (xmlAsString.charCodeAt(pos));
// inline /[a-zA-Z0-9_:-]/.test(xmlAsString[pos])

@@ -144,3 +112,3 @@ if (

) {
pos += 1
pos += 1;
continue

@@ -150,10 +118,20 @@ }

}
const str = xmlAsString.slice(start, pos)
return replaceQuotes(str)
}
return xmlAsString.slice(start, pos)
};
const readAlphaNumericAndSpecialChars = () => {
let start = pos
const replaceQuotes = ($str) => {
let output = '';
let fromIndex = 0;
let index = 0;
while ((index = $str.indexOf("'", fromIndex)) !== -1) {
output = output + $str.slice(fromIndex, index) + '"';
fromIndex = index + 1;
}
return fromIndex ? output + $str.slice(fromIndex) : $str
};
const skipAlphaNumericAndSpecialChars = () => {
const start = pos;
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
const code = (xmlAsString.charCodeAt(pos));
// inline /[^>=<]/u.test(xmlAsString[pos])

@@ -165,3 +143,3 @@ if (

) {
pos += 1
pos += 1;
continue

@@ -171,134 +149,387 @@ }

}
const str = xmlAsString.slice(start, pos)
return replaceQuotes(str)
}
return pos > start
};
const skipTagName = () => {
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[a-zA-Z0-9_:-]/.test(xmlAsString[pos])
if (
(code >= 97 && code <= 122) ||
(code >= 65 && code <= 90) ||
(code >= 48 && code <= 57) ||
code === 95 ||
code === 58 ||
code === 45
) {
pos += 1;
continue
}
break
}
};
const next = () => {
let eating = true
eatingLoop: while (eating) {
eating = false
const prevPos = pos
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 32 ||
let skippingScope = null;
let skippingAttrib = false;
while (true) {
if (skippingScope === null) {
let prevPos = pos;
if (peekedPos === 0) {
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1
continue
pos += 1;
continue
}
break
}
} else if (peekedTokenType === 9) {
pos = peekedPos;
peekedPos = 0;
peekedTagName = '';
peekedTokenType = 0;
}
break
if (!((pos < length))) {
currToken = EOF_TOKEN;
currTokenType = 9;
return currToken
}
if ((currTokenType === 1)) {
// starting new element
const tagName = peekedTagName;
pos = peekedPos;
peekedPos = 0;
peekedTagName = '';
peekedTokenType = 0;
currScope = { tagName };
currTokenType = 2;
currToken = ({
type: 2,
value: tagName
});
scoping.push(currScope);
return currToken
}
if ((currTokenType === 5)) {
// assign value to attribute
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 34 || code === 39)) {
pos += 1;
}
}
const numOfSpacesSkipped = pos - prevPos
if (!((pos < length))) {
currentToken = EOF_TOKEN
return currentToken
} else if ((currentToken && currentToken.type === 1)) {
// starting new element
let start = pos;
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 34 || code === 39)) {
break
}
pos += 1;
}
currTokenType = 4;
if (skippingAttrib) {
skippingAttrib = false;
pos += 1;
continue
}
const str = xmlAsString.slice(start, pos);
const buffer = replaceQuotes(str);
pos += 1;
currToken = ({
type: 4,
value: buffer
});
return currToken
}
const numOfSpacesSkipped = pos - prevPos;
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 32 ||
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1
continue
}
break
}
pos += 1;
continue
}
break
}
const tagName = readAlphaNumericCharsAndBrackets()
currentToken = ({
type: 2,
value: tagName
})
scopingTagName.push(tagName)
} else if ((currentToken && currentToken.type === 5)) {
// assign value to attribute
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 34 || code === 39)) {
pos += 1
switch (readBracketsAsBitmask()) {
case 2: {
const prevPos = pos;
// peek at tag name
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1;
continue
}
break
}
peekedPos = pos;
if (!((pos < length))) {
peekedTokenType = 9;
} else {
peekedTokenType = 2;
peekedTagName = readTagName();
peekedPos = pos;
if (
typeof knownElement === 'function' &&
!knownElement(peekedTagName)
) {
const tagName = peekedTagName;
peekedPos = 0;
peekedTagName = '';
currScope = { tagName };
currTokenType = 2;
skippingScope = currScope;
skippingAttrib = true;
scoping.push(currScope);
break
}
}
// Restore pos after peeking so that the APIs report
// expected values for the current position/token.
pos = prevPos;
currTokenType = 1;
currToken = ({
type: 1,
value: ''
});
return currToken
}
}
let start = pos
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 34 || code === 39)) {
case 3: {
scoping.pop();
const start = pos;
while ((xmlAsString.charCodeAt(pos)) !== 62)
pos += 1;
currScope = scoping[scoping.length - 1];
currTokenType = 8;
currToken = ({
type: 8,
value: xmlAsString.slice(start, pos)
});
pos += 1; // skip the ">"
return currToken
}
case 4: {
currTokenType = 7;
currToken = ({
type: 7,
value: ''
});
return currToken
}
case 5: {
const { tagName } = scoping.pop();
currScope = scoping[scoping.length - 1];
currTokenType = 8;
currToken = ({
type: 8,
value: tagName
});
return currToken
}
case 8: {
if (currTokenType === 3) {
currTokenType = 5;
if (skippingAttrib) break
currToken = ({
type: 5,
value: ''
});
return currToken
}
currTokenType = 6;
currToken = ({
type: 6,
value: '='
});
return currToken
}
case 16: {
// skipComment contents
const closingBuff = [
33,
45,
45
];
while (
(pos < length) &&
(closingBuff[2] !== 62 ||
closingBuff[1] !== 45 ||
closingBuff[0] !== 45)
) {
closingBuff.shift();
closingBuff.push((xmlAsString.charCodeAt(pos)));
pos += 1;
}
break
}
pos += 1
default: {
const buffer = readAlphaNumericAndSpecialChars();
if (buffer.length === 0) {
throw new Error(
`Unknown Syntax : "${xmlAsString[pos]}"`
)
}
// here we fall if we have alphanumeric string, which can be related to attributes, content or nothing
if (currTokenType === 7) {
currTokenType = 6;
currToken =
// prettier-ignore
(xmlAsString.charCodeAt(pos)) === 60
? ({
type: 6,
value: buffer
})
: ({
type: 6,
value: buffer +
readAlphaNumericAndSpecialChars()
});
return currToken
}
if (
currTokenType !== 3 &&
currTokenType !== 6
) {
if (currTokenType === 8) {
// we're assuming this is content, part of unstructured data
currTokenType = 6;
currToken = ({
type: 6,
value: ' '.repeat(numOfSpacesSkipped) + buffer
});
return currToken
}
// it should be an attribute name token
currTokenType = 3;
if (
typeof knownAttrib === 'function' &&
!knownAttrib(buffer)
) {
skippingAttrib = true;
break
}
currToken = ({
type: 3,
value: buffer
});
return currToken
}
currTokenType = 6;
currToken = ({
type: 6,
value: ' '.repeat(numOfSpacesSkipped) + buffer
});
return currToken
}
}
const str = xmlAsString.slice(start, pos)
const buffer = replaceQuotes(str)
pos += 1
currentToken = ({
type: 4,
value: buffer
})
} else {
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 32 ||
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1
continue
pos += 1;
continue
}
break
}
if (!((pos < length))) {
currToken = EOF_TOKEN;
currTokenType = 9;
return currToken
}
if ((currTokenType === 1)) {
// starting new element
skipTagName();
currScope = { tagName: '' };
currTokenType = 2;
scoping.push(currScope);
continue
}
if ((currTokenType === 5)) {
// assign value to attribute
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 34 || code === 39)) {
pos += 1;
}
}
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 34 || code === 39)) {
break
}
pos += 1;
}
break
pos += 1;
currTokenType = 4;
continue
}
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1;
continue
}
break
}
switch (readBracketsAsBitmask()) {
case 2: {
currentToken = ({
type: 1,
value: ''
})
currTokenType = 1;
break
}
case 3: {
const start = pos
const isDoneSkipping = scoping.pop() === skippingScope;
while ((xmlAsString.charCodeAt(pos)) !== 62)
pos += 1
currentToken = ({
type: 8,
value: xmlAsString.slice(start, pos)
})
pos += 1 // skip the ">"
scopingTagName.pop()
pos += 1;
currScope = scoping[scoping.length - 1];
currTokenType = 8;
if (isDoneSkipping) skippingScope = null;
pos += 1; // skip the ">"
break
}
case 4: {
currentToken = ({
type: 7,
value: ''
})
currTokenType = 7;
break
}
case 5: {
currentToken = ({
type: 8,
value: scopingTagName.pop()
})
const isDoneSkipping = scoping.pop() === skippingScope;
currScope = scoping[scoping.length - 1];
currTokenType = 8;
if (isDoneSkipping) skippingScope = null;
break
}
case 8: {
if (currentToken.type === 3) {
currentToken = ({
type: 5,
value: ''
})
} else {
currentToken = ({
type: 6,
value: '='
})
}
currTokenType =
currTokenType === 3
? 5
: 6;
break

@@ -312,3 +543,3 @@ }

45
]
];
while (

@@ -320,61 +551,33 @@ (pos < length) &&

) {
closingBuff.shift()
closingBuff.push((xmlAsString.charCodeAt(pos)))
pos += 1
closingBuff.shift();
closingBuff.push((xmlAsString.charCodeAt(pos)));
pos += 1;
}
eating = true
continue eatingLoop
break
}
default: {
const buffer = readAlphaNumericAndSpecialChars()
if (skipAlphaNumericAndSpecialChars() === false) {
throw new Error(
`Unknown Syntax : "${xmlAsString[pos]}"`
)
}
// here we fall if we have alphanumeric string, which can be related to attributes, content or nothing
if (buffer.length > 0) {
if (
currentToken.type === 7
) {
if (
(xmlAsString.charCodeAt(pos)) !== 60
) {
currentToken = ({
type: 6,
value: buffer +
readAlphaNumericAndSpecialChars()
})
} else {
currentToken = ({
type: 6,
value: buffer
})
}
} else if (
currentToken.type !== 3 &&
currentToken.type !== 6
) {
if (
currentToken.type ===
8
) {
if (currTokenType === 7) {
currTokenType = 6;
if ((xmlAsString.charCodeAt(pos)) !== 60) {
skipAlphaNumericAndSpecialChars();
}
} else if (
currTokenType !== 3 &&
currTokenType !== 6
) {
currTokenType =
// prettier-ignore
currTokenType === 8
// we're assuming this is content, part of unstructured data
currentToken = ({
type: 6,
value: ' '.repeat(numOfSpacesSkipped) + buffer
})
} else {
? 6
// it should be an attribute name token
currentToken = ({
type: 3,
value: buffer
})
}
} else {
currentToken = ({
type: 6,
value: ' '.repeat(numOfSpacesSkipped) + buffer
})
}
break
: 3;
} else {
throw new Error(
`Unknown Syntax : "${xmlAsString[pos]}"`
)
currTokenType = 6;
}

@@ -385,24 +588,22 @@ }

}
};
return currentToken
}
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos))
if ((code === 32 ||
while ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if ((code === 32 ||
code === 10 ||
code === 13 ||
code === 9)) {
pos += 1
continue
pos += 1;
continue
}
break
}
break
}
// inline xmlAsString.startsWith('<?xml', pos)
if (
(xmlAsString.charCodeAt(pos)) === 60 &&
// inline xmlAsString.startsWith('<?xml', pos)
if (
(xmlAsString.charCodeAt(pos)) === 60 &&
xmlAsString.charCodeAt(pos + 1) === 63 &&

@@ -412,17 +613,17 @@ xmlAsString.charCodeAt(pos + 2) === 120 &&

xmlAsString.charCodeAt(pos + 4) === 108
) {
while ((pos < length)) {
if ((xmlAsString.charCodeAt(pos)) !== 63) {
pos += 1
} else if (
xmlAsString.charCodeAt(pos + 1) === 62
) {
// skip "?>"
pos += 2
break
} else {
pos += 1
) {
while ((pos < length)) {
if ((xmlAsString.charCodeAt(pos)) !== 63) {
pos += 1;
} else if (
xmlAsString.charCodeAt(pos + 1) === 62
) {
// skip "?>"
pos += 2;
break
} else {
pos += 1;
}
}
}
}

@@ -432,7 +633,7 @@

return {
hasNextPos,
hasNextToken,
hasNext,
next,
peek,
pos: getPos,
scope: getScope,
// prettier-ignore

@@ -445,5 +646,5 @@ ...({})

createLexer: createLexer$1
}
};
const { createLexer } = lexer
const { createLexer } = lexer;

@@ -465,22 +666,24 @@ const createAST$2 = (xmlAsString) => {

*/
const lexer = createLexer(xmlAsString)
const lexer = createLexer(xmlAsString);
const rootNode = ({
type: 'ROOT',
value: {
children: [],
loc: { start: 0, end: xmlAsString.length }
}
})
const scopingNode = [rootNode]
type: "ROOT",
value: {
children: [],
loc: { start: 0, end: xmlAsString.length }
}
});
const scopingNode = [rootNode];
while (lexer.hasNextToken()) {
const tok = lexer.next()
const { value: nodeValue } = scopingNode[scopingNode.length - 1]
switch (tok.type) {
while (lexer.hasNext()) {
const tok = lexer.next();
const tokScope = lexer.scope();
const { type: tokType } = tok;
const { value: nodeValue } = scopingNode[scopingNode.length - 1];
switch (tokType) {
case 1: {
const start = lexer.pos() - 1
const { value: tagName } = lexer.next()
const attribs = []
let currTok = lexer.next()
let currType = currTok.type
const start = lexer.pos() - 1;
const { value: tagName } = lexer.next();
const attribs = [];
let currTok = lexer.next();
let currType = currTok.type;
while (

@@ -490,39 +693,38 @@ currType !== 7 &&

currType !== 9 &&
lexer.hasNextToken()
lexer.hasNext()
) {
const attribNameTok = currTok
lexer.next() // assignment token
const attribValueTok = lexer.next()
const attribNameTok = currTok;
lexer.next(); // assignment token
const attribValueTok = lexer.next();
attribs.push(
({
type: 'ATTRIBUTE',
value: {
name: attribNameTok.value,
value: attribValueTok.value
}
})
)
currTok = lexer.next()
currType = currTok.type
type: "ATTRIBUTE",
value: {
name: attribNameTok.value,
value: attribValueTok.value
}
})
);
currTok = lexer.next();
currType = currTok.type;
}
currType = currTok.type
const isSelfClosing =
currType === 8 ||
currType === 9
const end = isSelfClosing ? lexer.pos() : start
currType === 9;
const end = isSelfClosing ? lexer.pos() : start;
const childNode = ({
type: 'ELEMENT',
value: {
type: tagName,
attributes: attribs,
children: [],
loc: {
start,
end
}
}
})
nodeValue.children.push(childNode)
type: "ELEMENT",
value: {
type: tagName,
attributes: attribs,
children: [],
loc: {
start,
end
}
}
});
nodeValue.children.push(childNode);
if (!isSelfClosing) {
scopingNode.push(childNode)
scopingNode.push(childNode);
}

@@ -532,25 +734,25 @@ break

case 8: {
if (tok.value === nodeValue.type) {
scopingNode.pop()
nodeValue.loc.end = lexer.pos()
const { children } = nodeValue
const { length: childrenLength } = children
if (tokScope === lexer.scope()) {
scopingNode.pop();
nodeValue.loc.end = lexer.pos();
const { children } = nodeValue;
const { length: childrenLength } = children;
const firstChild =
childrenLength > 0 ? children[0] : undefined
if (firstChild && firstChild.type === 'CONTENT') {
let buffer = firstChild.value
const reduced = []
childrenLength > 0 ? children[0] : undefined;
if (firstChild && firstChild.type === "CONTENT") {
let buffer = firstChild.value;
const reduced = [];
for (let i = 1; i < childrenLength; i += 1) {
const child = children[i]
if (child.type === 'CONTENT') {
buffer = buffer + child.value
const child = children[i];
if (child.type === "CONTENT") {
buffer = buffer + child.value;
} else {
if (buffer.length) {
reduced.push(({
type: 'CONTENT',
value: buffer
}))
buffer = ''
type: "CONTENT",
value: buffer
}));
buffer = '';
}
reduced.push(child)
reduced.push(child);
}

@@ -560,7 +762,7 @@ }

reduced.push(({
type: 'CONTENT',
value: buffer
}))
type: "CONTENT",
value: buffer
}));
}
nodeValue.children = reduced
nodeValue.children = reduced;
}

@@ -572,5 +774,5 @@ }

nodeValue.children.push(({
type: 'CONTENT',
value: tok.value
}))
type: "CONTENT",
value: tok.value
}));
break

@@ -583,3 +785,3 @@ }

throw new Error(
`Unknown Lexem type: ${tok.type} "${tok.value}, scoping element: ${nodeValue.type}"`
`Unknown Lexem type: ${tokType} "${tok.value}, scoping element: ${nodeValue.type}"`
)

@@ -590,3 +792,3 @@ }

return rootNode
}
};

@@ -597,22 +799,22 @@ var parser = {

...({})
}
};
var astToJson
var hasRequiredAstToJson
var astToJson;
var hasRequiredAstToJson;
function requireAstToJson () {
if (hasRequiredAstToJson) return astToJson
hasRequiredAstToJson = 1
if (hasRequiredAstToJson) return astToJson;
hasRequiredAstToJson = 1;
const convertToJSON = ast => {
const root = ast.value.children[0]
const convertToJSON = ast => {
const root = ast.value.children[0];
if (typeof root !== 'object' || root === null) {
return null
}
const json = {}
const json = {};
// Use a queue to avoid call stack limits.
const queue = Array(1000)
queue[0] = [root, json, -1]
let queueLength = 1
let pos = 0
const queue = Array(1000);
queue[0] = [root, json, -1];
let queueLength = 1;
let pos = 0;
while (pos < queueLength) {

@@ -625,9 +827,9 @@ const {

2: parentArrayIndex
} = queue[pos++]
const parentIsArray = parentArrayIndex !== -1
const object = {}
} = queue[pos++];
const parentIsArray = parentArrayIndex !== -1;
const object = {};
if (parentIsArray) {
parent[parentArrayIndex] = { [key]: object }
parent[parentArrayIndex] = { [key]: object };
} else {
parent[key] = object
parent[key] = object;
}

@@ -637,21 +839,21 @@ for (let i = 0, { length } = attributes; i < length; i += 1) {

value: { name: attrName, value: attrValue }
} = attributes[i]
object[attrName] = attrValue
} = attributes[i];
object[attrName] = attrValue;
}
const { length: childrenLength } = children
const { length: childrenLength } = children;
if (!childrenLength) {
continue
}
if (childrenLength === 1 && children[0].type === 'CONTENT') {
object.content = children[0].value
if (childrenLength === 1 && children[0].type === "CONTENT") {
object.content = children[0].value;
continue
}
const childObjects = Array(childrenLength)
object.children = childObjects
const childObjects = Array(childrenLength);
object.children = childObjects;
for (let i = 0; i < childrenLength; i += 1) {
const childNode = children[i]
if (childNode.type === 'CONTENT') {
childObjects[i] = { content: childNode.value }
const childNode = children[i];
if (childNode.type === "CONTENT") {
childObjects[i] = { content: childNode.value };
} else {
queue[queueLength++] = [childNode, childObjects, i]
queue[queueLength++] = [childNode, childObjects, i];
}

@@ -661,11 +863,11 @@ }

return json
}
};
astToJson = {
astToJson = {
convert: convertToJSON
}
return astToJson
};
return astToJson;
}
const { createAST: createAST$1 } = parser
const { createAST: createAST$1 } = parser;

@@ -676,3 +878,3 @@ function convertXML$1(

) {
const ast = createAST$1(xmlAsString)
const ast = createAST$1(xmlAsString);
return converter ? converter.convert(ast) : ast

@@ -683,6 +885,6 @@ }

convertXML: convertXML$1
}
};
const { createAST } = parser
const { convertXML } = transpiler
const { createAST } = parser;
const { convertXML } = transpiler;

@@ -692,6 +894,6 @@ var xmlToJson = {

createAST
}
};
var xmlToJson$1 = /*@__PURE__*/getDefaultExportFromCjs(xmlToJson)
var xmlToJson$1 = /*@__PURE__*/getDefaultExportFromCjs(xmlToJson);
module.exports = xmlToJson$1
module.exports = xmlToJson$1;

@@ -1,1 +0,1 @@

"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}const t={type:9,value:""};var r={createLexer:function(e){const{length:r}=e,n=[];let o=null,c=0;const a=e=>{let t="",r=0,n=0;for(;-1!==(n=e.indexOf("'",r));)t=t+e.slice(r,n)+'"',r=n+1;return r?t+e.slice(r):e},l=()=>{if(c<r){const t=e.charCodeAt(c);if(60===t)return c+=1,c<r&&47===e.charCodeAt(c)?(c+=1,3):c<r&&33===e.charCodeAt(c)&&45===e.charCodeAt(c+1)&&45===e.charCodeAt(c+2)?(c+=3,16):2;if(47===t)return c+=1,c<r&&62===e.charCodeAt(c)?(c+=1,5):1;if(61===t)return c+=1,8;if(62===t)return c+=1,4}return 0},s=()=>{if(c<r){const t=e.charCodeAt(c);if(60===t)return c+=1,c<r&&47===e.charCodeAt(c)?(c+=1,"</"):c<r&&33===e.charCodeAt(c)&&45===e.charCodeAt(c+1)&&45===e.charCodeAt(c+2)?(c+=3,"\x3c!--"):"<";if(47===t)return c+=1,c<r&&62===e.charCodeAt(c)?(c+=1,"/>"):"/";if(61===t)return c+=1,"=";if(62===t)return c+=1,">"}return u()},u=()=>{let t=c;for(;c<r;){const t=e.charCodeAt(c);if(!(t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||58===t||45===t))break;c+=1}const n=e.slice(t,c);return a(n)},p=()=>{let t=c;for(;c<r;){const t=e.charCodeAt(c);if(60===t||61===t||62===t)break;c+=1}const n=e.slice(t,c);return a(n)};for(;c<r;){const t=e.charCodeAt(c);if(32!==t&&10!==t&&13!==t&&9!==t)break;c+=1}if(60===e.charCodeAt(c)&&63===e.charCodeAt(c+1)&&120===e.charCodeAt(c+2)&&109===e.charCodeAt(c+3)&&108===e.charCodeAt(c+4))for(;c<r;)if(63!==e.charCodeAt(c))c+=1;else{if(62===e.charCodeAt(c+1)){c+=2;break}c+=1}return{hasNextPos:()=>c<r,hasNextToken:()=>o!==t&&c<r,next:()=>{let u=!0;e:for(;u;){u=!1;const h=c;for(;c<r;){const t=e.charCodeAt(c);if(32!==t&&10!==t&&13!==t&&9!==t)break;c+=1}const i=c-h;if(!(c<r))return o=t,o;if(o&&1===o.type){for(;c<r;){const t=e.charCodeAt(c);if(32!==t&&10!==t&&13!==t&&9!==t)break;c+=1}const t=s();o={type:2,value:t},n.push(t)}else if(o&&5===o.type){if(c<r){const t=e.charCodeAt(c);34!==t&&39!==t||(c+=1)}let t=c;for(;c<r;){const t=e.charCodeAt(c);if(34===t||39===t)break;c+=1}const n=e.slice(t,c),l=a(n);c+=1,o={type:4,value:l}}else{for(;c<r;){const t=e.charCodeAt(c);if(32!==t&&10!==t&&13!==t&&9!==t)break;c+=1}switch(l()){case 2:o={type:1,value:""};break;case 3:{const t=c;for(;62!==e.charCodeAt(c);)c+=1;o={type:8,value:e.slice(t,c)},c+=1,n.pop();break}case 4:o={type:7,value:""};break;case 5:o={type:8,value:n.pop()};break;case 8:o=3===o.type?{type:5,value:""}:{type:6,value:"="};break;case 16:{const t=[33,45,45];for(;c<r&&(62!==t[2]||45!==t[1]||45!==t[0]);)t.shift(),t.push(e.charCodeAt(c)),c+=1;u=!0;continue e}default:{const t=p();if(t.length>0){o=7===o.type?60!==e.charCodeAt(c)?{type:6,value:t+p()}:{type:6,value:t}:3!==o.type&&6!==o.type?8===o.type?{type:6,value:" ".repeat(i)+t}:{type:3,value:t}:{type:6,value:" ".repeat(i)+t};break}throw new Error(`Unknown Syntax : "${e[c]}"`)}}}}return o},peek:()=>e.charCodeAt(c),pos:()=>c}}};const{createLexer:n}=r;var o,c,a={createAST:e=>{const t=n(e),r={type:"ROOT",value:{children:[],loc:{start:0,end:e.length}}},o=[r];for(;t.hasNextToken();){const e=t.next(),{value:n}=o[o.length-1];switch(e.type){case 1:{const e=t.pos()-1,{value:r}=t.next(),c=[];let a=t.next(),l=a.type;for(;7!==l&&8!==l&&9!==l&&t.hasNextToken();){const e=a;t.next();const r=t.next();c.push({type:"ATTRIBUTE",value:{name:e.value,value:r.value}}),a=t.next(),l=a.type}l=a.type;const s=8===l||9===l,u={type:"ELEMENT",value:{type:r,attributes:c,children:[],loc:{start:e,end:s?t.pos():e}}};n.children.push(u),s||o.push(u);break}case 8:if(e.value===n.type){o.pop(),n.loc.end=t.pos();const{children:e}=n,{length:r}=e,c=r>0?e[0]:void 0;if(c&&"CONTENT"===c.type){let t=c.value;const o=[];for(let n=1;n<r;n+=1){const r=e[n];"CONTENT"===r.type?t+=r.value:(t.length&&(o.push({type:"CONTENT",value:t}),t=""),o.push(r))}t.length&&o.push({type:"CONTENT",value:t}),n.children=o}}break;case 6:n.children.push({type:"CONTENT",value:e.value});break;case 9:return r;default:throw new Error(`Unknown Lexem type: ${e.type} "${e.value}, scoping element: ${n.type}"`)}}return r}};const{createAST:l}=a;var s={convertXML:function(e,t=function(){return c?o:(c=1,o={convert:e=>{const t=e.value.children[0];if("object"!=typeof t||null===t)return null;const r={},n=Array(1e3);n[0]=[t,r,-1];let o=1,c=0;for(;c<o;){const{0:{value:{attributes:e,children:t,type:r}},1:a,2:l}=n[c++],s={};-1!==l?a[l]={[r]:s}:a[r]=s;for(let t=0,{length:r}=e;t<r;t+=1){const{value:{name:r,value:n}}=e[t];s[r]=n}const{length:u}=t;if(!u)continue;if(1===u&&"CONTENT"===t[0].type){s.content=t[0].value;continue}const p=Array(u);s.children=p;for(let e=0;e<u;e+=1){const r=t[e];"CONTENT"===r.type?p[e]={content:r.value}:n[o++]=[r,p,e]}}return r}})}()){const r=l(e);return t?t.convert(r):r}};const{createAST:u}=a,{convertXML:p}=s;var h=e({convertXML:p,createAST:u});module.exports=h;
"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}const t={type:9,value:""};var r={createLexer:function(e,{knownAttrib:r,knownElement:n}={}){const{length:o}=e,c=[];let a=0,s=t,l=0,u=0,f="",i=0,h=0;const p=()=>{const t=h;for(;h<o;){const t=e.charCodeAt(h);if(60===t||61===t||62===t)break;h+=1}const r=e.slice(t,h);return A(r)},d=()=>{if(h<o){const t=e.charCodeAt(h);if(60===t)return h+=1,h<o&&47===e.charCodeAt(h)?(h+=1,3):h<o&&33===e.charCodeAt(h)&&45===e.charCodeAt(h+1)&&45===e.charCodeAt(h+2)?(h+=3,16):2;if(47===t)return h+=1,h<o&&62===e.charCodeAt(h)?(h+=1,5):1;if(61===t)return h+=1,8;if(62===t)return h+=1,4}return 0},v=()=>{let t=h;for(;h<o;){const t=e.charCodeAt(h);if(!(t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||58===t||45===t))break;h+=1}return e.slice(t,h)},A=e=>{let t="",r=0,n=0;for(;-1!==(n=e.indexOf("'",r));)t=t+e.slice(r,n)+'"',r=n+1;return r?t+e.slice(r):e},C=()=>{const t=h;for(;h<o;){const t=e.charCodeAt(h);if(60===t||61===t||62===t)break;h+=1}return h>t},y=()=>{for(;h<o;){const t=e.charCodeAt(h);if(!(t>=97&&t<=122||t>=65&&t<=90||t>=48&&t<=57||95===t||58===t||45===t))break;h+=1}};for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}if(60===e.charCodeAt(h)&&63===e.charCodeAt(h+1)&&120===e.charCodeAt(h+2)&&109===e.charCodeAt(h+3)&&108===e.charCodeAt(h+4))for(;h<o;)if(63!==e.charCodeAt(h))h+=1;else{if(62===e.charCodeAt(h+1)){h+=2;break}h+=1}return{hasNext:()=>h<o,next:()=>{let k=null,b=!1;for(;;)if(null===k){let C=h;if(0===u)for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}else 9===i&&(h=u,u=0,f="",i=0);if(!(h<o))return s=t,l=9,s;if(1===l){const e=f;return h=u,u=0,f="",i=0,a={tagName:e},l=2,s={type:2,value:e},c.push(a),s}if(5===l){if(h<o){const t=e.charCodeAt(h);34!==t&&39!==t||(h+=1)}let t=h;for(;h<o;){const t=e.charCodeAt(h);if(34===t||39===t)break;h+=1}if(l=4,b){b=!1,h+=1;continue}const r=e.slice(t,h),n=A(r);return h+=1,s={type:4,value:n},s}const y=h-C;for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}switch(d()){case 2:{const t=h;for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}if(u=h,h<o){if(i=2,f=v(),u=h,"function"==typeof n&&!n(f)){const e=f;u=0,f="",a={tagName:e},l=2,k=a,b=!0,c.push(a);break}}else i=9;return h=t,l=1,s={type:1,value:""},s}case 3:{c.pop();const t=h;for(;62!==e.charCodeAt(h);)h+=1;return a=c[c.length-1],l=8,s={type:8,value:e.slice(t,h)},h+=1,s}case 4:return l=7,s={type:7,value:""},s;case 5:{const{tagName:e}=c.pop();return a=c[c.length-1],l=8,s={type:8,value:e},s}case 8:if(3===l){if(l=5,b)break;return s={type:5,value:""},s}return l=6,s={type:6,value:"="},s;case 16:{const t=[33,45,45];for(;h<o&&(62!==t[2]||45!==t[1]||45!==t[0]);)t.shift(),t.push(e.charCodeAt(h)),h+=1;break}default:{const t=p();if(0===t.length)throw new Error(`Unknown Syntax : "${e[h]}"`);if(7===l)return l=6,s=60===e.charCodeAt(h)?{type:6,value:t}:{type:6,value:t+p()},s;if(3!==l&&6!==l){if(8===l)return l=6,s={type:6,value:" ".repeat(y)+t},s;if(l=3,"function"==typeof r&&!r(t)){b=!0;break}return s={type:3,value:t},s}return l=6,s={type:6,value:" ".repeat(y)+t},s}}}else{for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}if(!(h<o))return s=t,l=9,s;if(1===l){y(),a={tagName:""},l=2,c.push(a);continue}if(5===l){if(h<o){const t=e.charCodeAt(h);34!==t&&39!==t||(h+=1)}for(;h<o;){const t=e.charCodeAt(h);if(34===t||39===t)break;h+=1}h+=1,l=4;continue}for(;h<o;){const t=e.charCodeAt(h);if(32!==t&&10!==t&&13!==t&&9!==t)break;h+=1}switch(d()){case 2:l=1;break;case 3:{const t=c.pop()===k;for(;62!==e.charCodeAt(h);)h+=1;a=c[c.length-1],l=8,t&&(k=null),h+=1;break}case 4:l=7;break;case 5:{const e=c.pop()===k;a=c[c.length-1],l=8,e&&(k=null);break}case 8:l=3===l?5:6;break;case 16:{const t=[33,45,45];for(;h<o&&(62!==t[2]||45!==t[1]||45!==t[0]);)t.shift(),t.push(e.charCodeAt(h)),h+=1;break}default:if(!1===C())throw new Error(`Unknown Syntax : "${e[h]}"`);7===l?(l=6,60!==e.charCodeAt(h)&&C()):l=3!==l&&6!==l?8===l?6:3:6}}},peek:()=>e.charCodeAt(h),pos:()=>h,scope:()=>a}}};const{createLexer:n}=r;var o,c,a={createAST:e=>{const t=n(e),r={type:"ROOT",value:{children:[],loc:{start:0,end:e.length}}},o=[r];for(;t.hasNext();){const e=t.next(),n=t.scope(),{type:c}=e,{value:a}=o[o.length-1];switch(c){case 1:{const e=t.pos()-1,{value:r}=t.next(),n=[];let c=t.next(),s=c.type;for(;7!==s&&8!==s&&9!==s&&t.hasNext();){const e=c;t.next();const r=t.next();n.push({type:"ATTRIBUTE",value:{name:e.value,value:r.value}}),c=t.next(),s=c.type}const l=8===s||9===s,u={type:"ELEMENT",value:{type:r,attributes:n,children:[],loc:{start:e,end:l?t.pos():e}}};a.children.push(u),l||o.push(u);break}case 8:if(n===t.scope()){o.pop(),a.loc.end=t.pos();const{children:e}=a,{length:r}=e,n=r>0?e[0]:void 0;if(n&&"CONTENT"===n.type){let t=n.value;const o=[];for(let n=1;n<r;n+=1){const r=e[n];"CONTENT"===r.type?t+=r.value:(t.length&&(o.push({type:"CONTENT",value:t}),t=""),o.push(r))}t.length&&o.push({type:"CONTENT",value:t}),a.children=o}}break;case 6:a.children.push({type:"CONTENT",value:e.value});break;case 9:return r;default:throw new Error(`Unknown Lexem type: ${c} "${e.value}, scoping element: ${a.type}"`)}}return r}};const{createAST:s}=a;var l={convertXML:function(e,t=function(){return c?o:(c=1,o={convert:e=>{const t=e.value.children[0];if("object"!=typeof t||null===t)return null;const r={},n=Array(1e3);n[0]=[t,r,-1];let o=1,c=0;for(;c<o;){const{0:{value:{attributes:e,children:t,type:r}},1:a,2:s}=n[c++],l={};-1!==s?a[s]={[r]:l}:a[r]=l;for(let t=0,{length:r}=e;t<r;t+=1){const{value:{name:r,value:n}}=e[t];l[r]=n}const{length:u}=t;if(!u)continue;if(1===u&&"CONTENT"===t[0].type){l.content=t[0].value;continue}const f=Array(u);l.children=f;for(let e=0;e<u;e+=1){const r=t[e];"CONTENT"===r.type?f[e]={content:r.value}:n[o++]=[r,f,e]}}return r}})}()){const r=s(e);return t?t.convert(r):r}};const{createAST:u}=a,{convertXML:f}=l;var i=e({convertXML:f,createAST:u});module.exports=i;

@@ -25,3 +25,3 @@ {

"license": "MIT",
"version": "1.2.6",
"version": "1.2.7",
"author": "John-David <john.david.dalton@gmail.com>",

@@ -28,0 +28,0 @@ "main": "lib/simpleXmlToJson.min.js",