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.13

342

lib/simpleXmlToJson.js

@@ -13,3 +13,3 @@ 'use strict';

function createLexer$1(xmlAsString, { knownAttrib, knownElement } = {}) {
const { length } = xmlAsString;
const { length: xmlLength } = xmlAsString;
const scoping = [];

@@ -19,2 +19,3 @@ let currScope = 0;

let currTokenType = 0;
let isErrored = 0;
let peekedPos = 0;

@@ -24,2 +25,3 @@ let peekedTagName = '';

let pos = 0;
let erroredMessage;

@@ -29,9 +31,10 @@ const getPos = () => pos;

const peek = () => xmlAsString.charCodeAt(pos);
const hasNext = () => pos < length;
const hasNext = () => pos < xmlLength;
const readAlphaNumericAndSpecialChars = () => {
const start = pos;
while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[^>=<]/u.test(xmlAsString[pos])
// inline /[^>=<]/.test(xmlAsString[pos])
if (

@@ -47,2 +50,3 @@ code !== 60 &&

}
const str = xmlAsString.slice(start, pos);

@@ -53,41 +57,55 @@ return replaceQuotes(str)

const readBracketsAsBitmask = () => {
if ((pos < length)) {
const code = (xmlAsString.charCodeAt(pos));
if (code === 60) {
pos += 1;
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 47
) {
if ((pos < xmlLength)) {
switch ((xmlAsString.charCodeAt(pos))) {
case 60: {
pos += 1;
return 3
if (
(pos < xmlLength) &&
(xmlAsString.charCodeAt(pos)) === 47
) {
pos += 1;
return 3
}
if ((pos + 2 < xmlLength &&
xmlAsString.charCodeAt(pos) === 33 &&
xmlAsString.charCodeAt(pos + 1) === 45 &&
xmlAsString.charCodeAt(pos + 2) === 45)) {
// its a comment
pos += 3;
return 32
}
if ((pos + 7 < xmlLength &&
xmlAsString.charCodeAt(pos) === 33 &&
xmlAsString.charCodeAt(pos + 1) === 91 &&
xmlAsString.charCodeAt(pos + 2) === 67 &&
xmlAsString.charCodeAt(pos + 3) === 68 &&
xmlAsString.charCodeAt(pos + 4) === 65 &&
xmlAsString.charCodeAt(pos + 5) === 84 &&
xmlAsString.charCodeAt(pos + 6) === 65 &&
xmlAsString.charCodeAt(pos + 7) === 91)) {
// is CDATA
pos += 8;
return 16
}
return 2
}
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 33 &&
xmlAsString.charCodeAt(pos + 1) === 45 &&
xmlAsString.charCodeAt(pos + 2) === 45
) {
// its a comment
pos += 3;
return 16
case 47: {
pos += 1;
if (
(pos < xmlLength) &&
(xmlAsString.charCodeAt(pos)) === 62
) {
pos += 1;
return 5
}
return 1
}
return 2
}
if (code === 47) {
pos += 1;
if (
(pos < length) &&
(xmlAsString.charCodeAt(pos)) === 62
) {
case 61: {
pos += 1;
return 5
return 8
}
return 1
} else if (code === 61) {
pos += 1;
return 8
} else if (code === 62) {
pos += 1;
return 4
case 62: {
pos += 1;
return 4
}
}

@@ -98,7 +116,39 @@ }

const readCData = () => {
const start = pos;
while (!((pos < xmlLength &&
(
pos + 2 >= xmlLength ||
(
xmlAsString.charCodeAt(pos + 2) === 62 &&
xmlAsString.charCodeAt(pos + 1) === 93 &&
xmlAsString.charCodeAt(pos) === 93
)
)))) {
pos += 1;
}
const str = xmlAsString.slice(start, pos);
if (pos !== xmlLength) pos += 3;
return str
};
const readTagName = () => {
let start = pos;
while ((pos < length)) {
const start = pos;
let isFirstChar = true;
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[a-zA-Z0-9_:-]/.test(xmlAsString[pos])
// A tag name can start with ONLY [a-zA-Z] characters.
if (isFirstChar) {
isFirstChar = false;
if (
(code >= 97 && code <= 122) ||
(code >= 65 && code <= 90)
) {
pos += 1;
continue
}
isErrored = 1;
}
// The rest of the tag name can contain [a-zA-Z0-9_:.-] characters.
if (

@@ -110,2 +160,3 @@ (code >= 97 && code <= 122) ||

code === 58 ||
code === 46 ||
code === 45

@@ -118,2 +169,3 @@ ) {

}
return xmlAsString.slice(start, pos)

@@ -134,6 +186,5 @@ };

const skipAlphaNumericAndSpecialChars = () => {
const start = pos;
while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[^>=<]/u.test(xmlAsString[pos])
// inline /[^>=<]/.test(xmlAsString[pos])
if (

@@ -149,9 +200,21 @@ code !== 60 &&

}
return pos > start
};
const skipTagName = () => {
while ((pos < length)) {
let isFirstChar = true;
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));
// inline /[a-zA-Z0-9_:-]/.test(xmlAsString[pos])
// A tag name can start with ONLY [a-zA-Z] characters.
if (isFirstChar) {
isFirstChar = false;
if (
(code >= 97 && code <= 122) ||
(code >= 65 && code <= 90)
) {
pos += 1;
continue
}
isErrored = 1;
}
// The rest of the tag name can contain [a-zA-Z0-9_:.-] characters.
if (

@@ -163,2 +226,3 @@ (code >= 97 && code <= 122) ||

code === 58 ||
code === 46 ||
code === 45

@@ -174,2 +238,9 @@ ) {

const next = () => {
if (isErrored) {
isErrored = 1;
erroredMessage = erroredMessage;
throw new Error(erroredMessage)
}
let skippingScope = null;

@@ -182,3 +253,3 @@ let skippingAttrib = false;

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -201,3 +272,3 @@ if ((code === 32 ||

}
if (!((pos < length))) {
if (!((pos < xmlLength))) {
currToken = EOF_TOKEN;

@@ -226,3 +297,3 @@ currTokenType = 9;

if ((pos < length)) {
if ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -235,3 +306,3 @@ if ((code === 34 || code === 39)) {

let start = pos;
while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -260,3 +331,3 @@ if ((code === 34 || code === 39)) {

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -278,3 +349,3 @@ if ((code === 32 ||

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -292,7 +363,16 @@ if ((code === 32 ||

peekedPos = pos;
if (!((pos < length))) {
if (!((pos < xmlLength))) {
peekedTokenType = 9;
} else {
const start = pos;
peekedTagName = readTagName();
isErrored |= pos === start;
if (isErrored) {
isErrored = 1;
erroredMessage = `Invalid tag name: "${peekedTagName}"`;
throw new Error(`Invalid tag name: "${peekedTagName}"`)
}
peekedTokenType = 2;
peekedTagName = readTagName();
peekedPos = pos;

@@ -327,3 +407,5 @@ if (

const start = pos;
while ((xmlAsString.charCodeAt(pos)) !== 62)
while (
(xmlAsString.charCodeAt(pos)) !== 62
)
pos += 1;

@@ -375,18 +457,24 @@ currScope = scoping[scoping.length - 1];

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;
}
currTokenType = 6;
currToken = ({
type: 6,
value: readCData()
});
return currToken
}
case 32: {
while (!((pos < xmlLength &&
(
pos + 2 >= xmlLength ||
(
xmlAsString.charCodeAt(pos + 2) === 62 &&
xmlAsString.charCodeAt(pos + 1) === 45 &&
xmlAsString.charCodeAt(pos) === 45
)
)))) {
pos += 1;
}
if (pos !== xmlLength) pos += 3;
break

@@ -397,5 +485,7 @@ }

if (buffer.length === 0) {
throw new Error(
`Unknown Syntax : "${xmlAsString[pos]}"`
)
isErrored = 1;
erroredMessage = `Unknown Syntax : "${xmlAsString[pos]}"`;
throw new Error(`Unknown Syntax : "${xmlAsString[pos]}"`)
}

@@ -457,3 +547,3 @@ // here we fall if we have alphanumeric string, which can be related to attributes, content or nothing

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -470,3 +560,3 @@ if ((code === 32 ||

if (!((pos < length))) {
if (!((pos < xmlLength))) {
currToken = EOF_TOKEN;

@@ -478,3 +568,12 @@ currTokenType = 9;

// starting new element
const start = pos;
skipTagName();
isErrored |= pos === start;
if (isErrored) {
isErrored = 1;
erroredMessage = `Invalid tag name: "${xmlAsString.slice(start, pos)}"`;
throw new Error(`Invalid tag name: "${xmlAsString.slice(start, pos)}"`)
}
currScope = { tagName: '' };

@@ -488,3 +587,3 @@ currTokenType = 2;

if ((pos < length)) {
if ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -496,3 +595,3 @@ if ((code === 34 || code === 39)) {

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -509,3 +608,3 @@ if ((code === 34 || code === 39)) {

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -529,3 +628,5 @@ if ((code === 32 ||

const isDoneSkipping = scoping.pop() === skippingScope;
while ((xmlAsString.charCodeAt(pos)) !== 62)
while (
(xmlAsString.charCodeAt(pos)) !== 62
)
pos += 1;

@@ -557,25 +658,44 @@ currScope = scoping[scoping.length - 1];

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;
}
while (!((pos < xmlLength &&
(
pos + 2 >= xmlLength ||
(
xmlAsString.charCodeAt(pos + 2) === 62 &&
xmlAsString.charCodeAt(pos + 1) === 93 &&
xmlAsString.charCodeAt(pos) === 93
)
)))) {
pos += 1;
}
if (pos !== xmlLength) pos += 3;
break
}
case 32: {
while (!((pos < xmlLength &&
(
pos + 2 >= xmlLength ||
(
xmlAsString.charCodeAt(pos + 2) === 62 &&
xmlAsString.charCodeAt(pos + 1) === 45 &&
xmlAsString.charCodeAt(pos) === 45
)
)))) {
pos += 1;
}
if (pos !== xmlLength) pos += 3;
break
}
default: {
if (skipAlphaNumericAndSpecialChars() === false) {
throw new Error(
`Unknown Syntax : "${xmlAsString[pos]}"`
)
const start = pos;
skipAlphaNumericAndSpecialChars();
if (pos === start) {
isErrored = 1;
erroredMessage = `Unknown Syntax : "${xmlAsString[pos]}"`;
throw new Error(`Unknown Syntax : "${xmlAsString[pos]}"`)
}

@@ -585,3 +705,6 @@ // here we fall if we have alphanumeric string, which can be related to attributes, content or nothing

currTokenType = 6;
if ((xmlAsString.charCodeAt(pos)) !== 60) {
if (
(xmlAsString.charCodeAt(pos)) !==
60
) {
skipAlphaNumericAndSpecialChars();

@@ -611,3 +734,3 @@ }

while ((pos < length)) {
while ((pos < xmlLength)) {
const code = (xmlAsString.charCodeAt(pos));

@@ -633,7 +756,8 @@ if ((code === 32 ||

) {
while ((pos < length)) {
while ((pos < xmlLength)) {
if ((xmlAsString.charCodeAt(pos)) !== 63) {
pos += 1;
} else if (
xmlAsString.charCodeAt(pos + 1) === 62
xmlAsString.charCodeAt(pos + 1) ===
62
) {

@@ -672,8 +796,8 @@ // skip "?>"

| expr: StructuredXML | UnstructuredXML | Content
| StructuredXML: (openBracket + ElementName) + (AttributeList)* + closeBracket + (expr)* + closeElement
| StructuredXML: (openAngleBracket + ElementName) + (AttributeList)* + closeAngleBracket + (expr)* + closeElement
| UnstructuredXML: Content* + expr* + Content*
| Content: String
| openBracket: <
| closeBracket: >
| closeElement: </ + ElementName + closeBracket
| openAngleBracket: <
| closeAngleBracket: >
| closeElement: </ + ElementName + closeAngleBracket
| ElementName: String

@@ -680,0 +804,0 @@ | AttributeList: AttributeName + "=" + AttributeValue + AttributeList*

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

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

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

@@ -36,7 +36,7 @@ "main": "lib/simpleXmlToJson.min.js",

"build": "npm run clean && rollup -c --inline",
"clean": "rm -rf ./lib/ && mkdir lib ",
"clean": "rm -rf ./lib/ && mkdir lib",
"lint": "eslint ./src ./test",
"prettify": "prettier --write ./**/*.js",
"example": "node example/example.js",
"test": "jest ",
"test": "npm run build && jest",
"make-new-release-lib": "npm run validate-lib-health && sh ./scripts/make-new-release.sh",

@@ -64,3 +64,3 @@ "validate-lib-health": "npm run prettify && npm run lint && npm test"

"magic-string": "^0.30.10",
"prettier": "3.2.5",
"prettier": "^3.2.5",
"rollup": "^4.17.1"

@@ -67,0 +67,0 @@ },