Skip to content

Commit

Permalink
filter out null objects (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengling-zingbox committed Jan 10, 2021
1 parent c91efe0 commit b024735
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/extractor.ts
Expand Up @@ -253,7 +253,7 @@ export function extract(context: string, fields) {
index: ['Name'],
attributePath: ['AttributeValue'],
attributes: []
}
}
*/
if (index && attributePath) {
// find the index in localpath
Expand Down Expand Up @@ -309,7 +309,7 @@ export function extract(context: string, fields) {
value = node[0].toString();
}
if (node.length > 1) {
value = node.map(n => n.toString());
value = node.map(n => n.toString());
}
return {
...result,
Expand All @@ -330,7 +330,7 @@ export function extract(context: string, fields) {
const childXPath = `${buildAbsoluteXPath([last(localPath)])}${attributeXPath}`;
const attributeValues = baseNode.map((node: string) => {
const nodeDoc = new dom().parseFromString(node);
const values = select(childXPath, nodeDoc).reduce((r: any, n: Attr) => {
const values = select(childXPath, nodeDoc).reduce((r: any, n: Attr) => {
r[camelCase(n.name)] = n.value;
return r;
}, {});
Expand Down Expand Up @@ -373,7 +373,8 @@ export function extract(context: string, fields) {
attributeValue = select(fullPath, targetDoc);
}
if (node.length > 1) {
attributeValue = node.map((n: Node) => n.firstChild!.nodeValue);
attributeValue = node.filter((n: Node) => n.firstChild)
.map((n: Node) => n.firstChild!.nodeValue);
}
return {
...result,
Expand Down

0 comments on commit b024735

Please sign in to comment.