From b02473541a7ed7b85ee5e830fcbcd758313ccc5e Mon Sep 17 00:00:00 2001 From: zengling-zingbox <36426752+zengling-zingbox@users.noreply.github.com> Date: Sun, 10 Jan 2021 08:35:20 +0800 Subject: [PATCH] filter out null objects (#398) --- src/extractor.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/extractor.ts b/src/extractor.ts index f128f4e5..5d4449f3 100644 --- a/src/extractor.ts +++ b/src/extractor.ts @@ -253,7 +253,7 @@ export function extract(context: string, fields) { index: ['Name'], attributePath: ['AttributeValue'], attributes: [] - } + } */ if (index && attributePath) { // find the index in localpath @@ -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, @@ -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; }, {}); @@ -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,