Skip to content

Commit

Permalink
chore!: rename node.attrsMap to node.attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Sep 3, 2021
1 parent 4501cb4 commit a630b11
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/XMLNode.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export class XMLNode {
constructor(tagName, parent, val) {
constructor(tagName, parent, value) {
this.tagName = tagName;
this.parent = parent;
this.children = Object.create({}); //child tags
this.attrsMap = Object.create({}); //attributes map
this.val = val; //text only
this.attributes = Object.create({}); //attributes map
this.val = value; //text only
this.startIndex = -1;
}
addChild(child) {
Expand Down
14 changes: 10 additions & 4 deletions src/traversable/getTraversable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export function getTraversable(xmlData, options) {
options.stopNodes.includes(currentNode.tagName)
) {
currentNode.children = [];
if (currentNode.attrsMap === undefined) {
currentNode.attrsMap = {};
if (currentNode.attributes === undefined) {
currentNode.attributes = {};
}
currentNode.val = xmlData.subarray(currentNode.startIndex + 1, i);
}
Expand Down Expand Up @@ -191,7 +191,10 @@ export function getTraversable(xmlData, options) {

const childNode = new XMLNode(tagName, currentNode, '');
if (tagAttributes) {
childNode.attrsMap = parseAttributesString(tagAttributes, options);
childNode.attributes = parseAttributesString(
tagAttributes,
options,
);
}
currentNode.addChild(childNode);
} else {
Expand All @@ -205,7 +208,10 @@ export function getTraversable(xmlData, options) {
childNode.startIndex = closeIndex;
}
if (tagAttributes && shouldBuildAttributesMap) {
childNode.attrsMap = parseAttributesString(tagAttributes, options);
childNode.attributes = parseAttributesString(
tagAttributes,
options,
);
}
currentNode.addChild(childNode);
currentNode = childNode;
Expand Down
4 changes: 2 additions & 2 deletions src/traversableToJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function traversableToJSON(node, options, parentTagName) {
// when no child node or attr is present
if (
(!node.children || isEmptyObject(node.children)) &&
(!node.attrsMap || isEmptyObject(node.attrsMap))
(!node.attributes || isEmptyObject(node.attributes))
) {
return node.val === undefined ? '' : node.val;
}
Expand All @@ -38,7 +38,7 @@ export function traversableToJSON(node, options, parentTagName) {
result[options.textNodeName] = asArray ? [node.val] : node.val;
}

merge(result, node.attrsMap, arrayMode);
merge(result, node.attributes, arrayMode);

const keys = Object.keys(node.children);
for (let index = 0; index < keys.length; index++) {
Expand Down

0 comments on commit a630b11

Please sign in to comment.