From d6e33651ab10d58b322c6d7c6ab4922715228a4d Mon Sep 17 00:00:00 2001 From: nkzawa Date: Wed, 12 Feb 2020 12:07:45 +0900 Subject: [PATCH] skip showing data when the value of structured data is undefined --- index.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index f6fb5dd..0b86e0e 100644 --- a/index.ts +++ b/index.ts @@ -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(''); }