Merge pull request #19 from zeit/sd-skip-undefined

Skip showing data when the value of structured data is undefined
This commit is contained in:
Naoyuki Kanezawa 2020-02-12 12:09:14 +09:00 committed by GitHub
commit 5e4f34da76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1452,11 +1452,17 @@ export class RFC5424 extends RFC {
return '[' + [
sdId,
...Object.entries(sdParam)
.reduce((array, [name, value]) => [
...array,
...(Array.isArray(value) ? value : [value])
.map((v) => `${name}="${RFC5424.escapeParamValue(v)}"`),
], []),
.reduce((array, [name, value]) => {
if (typeof value === 'undefined') {
return array;
}
return [
...array,
...(Array.isArray(value) ? value : [value])
.map((v) => `${name}="${RFC5424.escapeParamValue(v || '')}"`),
];
}, []),
].join(' ') + ']';
}).join('');
}