Skip to content

Commit

Permalink
remove useless logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasNickel committed Dec 3, 2021
1 parent 467aa45 commit 0dddcb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txml",
"version": "5.1.0",
"version": "5.1.1",
"description": "fastest XML DOM Parser for node/browser/worker",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -60,4 +60,4 @@
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.2.3"
}
}
}
47 changes: 23 additions & 24 deletions tXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function parse(S, options) {
var doubleQuoteCC = '"'.charCodeAt(0);
var openCornerBracketCC = '['.charCodeAt(0);
var closeCornerBracketCC = ']'.charCodeAt(0);


/**
* parsing a list of entries
Expand All @@ -73,9 +73,9 @@ export function parse(S, options) {
while (S[pos]) {
if (S.charCodeAt(pos) == openBracketCC) {
if (S.charCodeAt(pos + 1) === slashCC) {
var closeStart= pos+2;
var closeStart = pos + 2;
pos = S.indexOf(closeBracket, pos);

var closeTag = S.substring(closeStart, pos)
if (closeTag.indexOf(tagName) == -1) {
var parsedText = S.substring(0, pos).split('\n');
Expand Down Expand Up @@ -103,29 +103,29 @@ export function parse(S, options) {
children.push(S.substring(startCommentPos, pos + 1));
}
} else if (
S.charCodeAt(pos + 2) === openCornerBracketCC
&& S.charCodeAt(pos + 8) === openCornerBracketCC
&& S.substr(pos+3, 5).toLowerCase() === 'cdata'
S.charCodeAt(pos + 2) === openCornerBracketCC &&
S.charCodeAt(pos + 8) === openCornerBracketCC &&
S.substr(pos + 3, 5).toLowerCase() === 'cdata'
) {
// cdata
var cdataEndIndex = S.indexOf(']]>', pos);
if (cdataEndIndex==-1) {
children.push(S.substr(pos+9));
pos=S.length;
if (cdataEndIndex == -1) {
children.push(S.substr(pos + 9));
pos = S.length;
} else {
children.push(S.substring(pos+9, cdataEndIndex));
children.push(S.substring(pos + 9, cdataEndIndex));
pos = cdataEndIndex + 3;
}
continue;
} else {
// doctypesupport
const startDoctype = pos+1;
const startDoctype = pos + 1;
pos += 2;
var encapsuled = false;
while ((S.charCodeAt(pos) !== closeBracketCC || encapsuled === true) && S[pos] ) {
while ((S.charCodeAt(pos) !== closeBracketCC || encapsuled === true) && S[pos]) {
if (S.charCodeAt(pos) === openCornerBracketCC) {
encapsuled = true;
} else if (encapsuled===true && S.charCodeAt(pos) === closeCornerBracketCC) {
} else if (encapsuled === true && S.charCodeAt(pos) === closeCornerBracketCC) {
encapsuled = false;
}
pos++;
Expand Down Expand Up @@ -256,7 +256,7 @@ export function parse(S, options) {

function parseString() {
var startChar = S[pos];
var startpos = pos+1;
var startpos = pos + 1;
pos = S.indexOf(startChar, startpos)
return S.slice(startpos, pos);
}
Expand Down Expand Up @@ -333,8 +333,7 @@ export function simplify(children) {
out[child.tagName] = [];
var kids = simplify(child.children);
out[child.tagName].push(kids);
if (Object.keys(child.attributes).length && typeof kids !=='string') {
console.log('kids', kids)
if (Object.keys(child.attributes).length && typeof kids !== 'string') {
kids._attributes = child.attributes;
}
});
Expand All @@ -353,8 +352,8 @@ export function simplify(children) {
* similar to simplify, but lost less
*
* @param {tNode[]} children the childrenList
*/
export function simplifyLostLess(children, parentAttributes={}) {
*/
export function simplifyLostLess(children, parentAttributes = {}) {
var out = {};
if (!children.length) {
return out;
Expand All @@ -364,7 +363,7 @@ export function simplifyLostLess(children, parentAttributes={}) {
return Object.keys(parentAttributes).length ? {
_attributes: parentAttributes,
value: children[0]
} :children[0];
} : children[0];
}
// map each object
children.forEach(function(child) {
Expand All @@ -373,7 +372,7 @@ export function simplifyLostLess(children, parentAttributes={}) {
}
if (!out[child.tagName])
out[child.tagName] = [];
var kids = simplifyLostLess(child.children||[], child.attributes);
var kids = simplifyLostLess(child.children || [], child.attributes);
out[child.tagName].push(kids);
if (Object.keys(child.attributes).length) {
kids._attributes = child.attributes;
Expand All @@ -388,12 +387,12 @@ export function simplifyLostLess(children, parentAttributes={}) {
* @params children{Array} the children of a node
* @param f{function} the filter method
*/
export function filter(children, f, dept=0,path='') {
export function filter(children, f, dept = 0, path = '') {
var out = [];
children.forEach(function(child, i) {
if (typeof(child) === 'object' && f(child, i, dept, path)) out.push(child);
if (child.children) {
var kids = filter(child.children, f, dept+1, (path?path+'.':'')+i+'.'+child.tagName);
var kids = filter(child.children, f, dept + 1, (path ? path + '.' : '') + i + '.' + child.tagName);
out = out.concat(kids);
}
});
Expand Down Expand Up @@ -433,7 +432,7 @@ export function stringify(O) {
out += ' ' + i + "='" + N.attributes[i].trim() + "'";
}
}
if(N.tagName[0]==='?'){
if (N.tagName[0] === '?') {
out += '?>';
return;
}
Expand Down Expand Up @@ -481,4 +480,4 @@ export function getElementsByClassName(S, classname, simplified) {
attrValue: '[a-zA-Z0-9- ]*' + classname + '[a-zA-Z0-9- ]*'
});
return simplified ? tXml.simplify(out) : out;
};
};

0 comments on commit 0dddcb2

Please sign in to comment.