Skip to content

Commit

Permalink
refactor!: rename node.val to node.value
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Sep 3, 2021
1 parent a630b11 commit 2b27e37
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/XMLNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class XMLNode {
this.parent = parent;
this.children = Object.create({}); //child tags
this.attributes = Object.create({}); //attributes map
this.val = value; //text only
this.value = value; //text only
this.startIndex = -1;
}
addChild(child) {
Expand Down
22 changes: 11 additions & 11 deletions src/traversable/getTraversable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export function getTraversable(xmlData, options) {
const value = options.trimValues
? arrayTrim(xmlData.subarray(dataIndex, dataIndex + dataSize))
: xmlData.subarray(dataIndex, dataIndex + dataSize);
if (currentNode.val === undefined) {
currentNode.val = value;
if (currentNode.value === undefined) {
currentNode.value = value;
} else {
currentNode.val = concat(currentNode.val, value);
currentNode.value = concat(currentNode.value, value);
}
}
if (
Expand All @@ -55,7 +55,7 @@ export function getTraversable(xmlData, options) {
if (currentNode.attributes === undefined) {
currentNode.attributes = {};
}
currentNode.val = xmlData.subarray(currentNode.startIndex + 1, i);
currentNode.value = xmlData.subarray(currentNode.startIndex + 1, i);
}
currentNode = currentNode.parent;
i = closeIndex;
Expand All @@ -78,8 +78,8 @@ export function getTraversable(xmlData, options) {
);
if (currentNode && dataSize !== 0) {
if (currentNode.tagName !== '!xml') {
currentNode.val = concat(
currentNode.val,
currentNode.value = concat(
currentNode.value,
options.trimValues
? arrayTrim(xmlData.subarray(dataIndex, dataSize + dataIndex))
: xmlData.subarray(dataIndex, dataSize + dataIndex),
Expand Down Expand Up @@ -122,7 +122,7 @@ export function getTraversable(xmlData, options) {
? arrayTrim(xmlData.subarray(dataIndex, dataIndex + dataSize))
: xmlData.subarray(dataIndex, dataIndex + dataSize);

currentNode.val = concat(currentNode.val, value);
currentNode.value = concat(currentNode.value, value);
}

if (options.cdataTagName) {
Expand All @@ -135,10 +135,10 @@ export function getTraversable(xmlData, options) {
currentNode.addChild(childNode);
//add rest value to parent node
if (tagExp) {
childNode.val = tagExp;
childNode.value = tagExp;
}
} else {
currentNode.val = concat(currentNode.val, tagExp);
currentNode.value = concat(currentNode.value, tagExp);
}

i = closeIndex + 2;
Expand Down Expand Up @@ -169,8 +169,8 @@ export function getTraversable(xmlData, options) {
//save text to parent node
if (currentNode && dataSize !== 0) {
if (currentNode.tagName !== '!xml') {
currentNode.val = concat(
currentNode.val,
currentNode.value = concat(
currentNode.value,
options.trimValues
? arrayTrim(xmlData.subarray(dataIndex, dataIndex + dataSize))
: xmlData.subarray(dataIndex, dataIndex + dataSize),
Expand Down
8 changes: 4 additions & 4 deletions src/traversable/parseAttributesString.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function parseAttributesString(string, options) {
return attributes;
}

function stringParseValue(val, shouldParse) {
if (shouldParse && typeof val === 'string') {
return parseString(val);
function stringParseValue(value, shouldParse) {
if (shouldParse && typeof value === 'string') {
return parseString(value);
} else {
return val === undefined ? '' : val;
return value === undefined ? '' : value;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/traversableToJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ export function traversableToJSON(node, options, parentTagName) {
const result = {};

if (tagValueProcessor) {
node.val = node.val && tagValueProcessor(node.val, node);
node.value = node.value && tagValueProcessor(node.value, node);
}
if (typeof node.val === 'string' && dynamicTypingNodeValue) {
node.val = parseString(node.val);
if (typeof node.value === 'string' && dynamicTypingNodeValue) {
node.value = parseString(node.value);
}
// when no child node or attr is present
if (
(!node.children || isEmptyObject(node.children)) &&
(!node.attributes || isEmptyObject(node.attributes))
) {
return node.val === undefined ? '' : node.val;
return node.value === undefined ? '' : node.value;
}

// otherwise create a textnode if node has some text
if (node.val !== undefined && node.val.length !== 0) {
if (node.value !== undefined && node.value.length !== 0) {
const asArray = isTagNameInArrayMode(
node.tagName,
arrayMode,
parentTagName,
);

result[options.textNodeName] = asArray ? [node.val] : node.val;
result[options.textNodeName] = asArray ? [node.value] : node.value;
}

merge(result, node.attributes, arrayMode);
Expand Down

0 comments on commit 2b27e37

Please sign in to comment.