From e5e4a65fcd86234150a29a365187d6ed9cfaa908 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Sat, 21 Dec 2024 03:24:18 +0900 Subject: [PATCH] Clarify helper function --- bin/api-docs/gen-components-docs/markdown/index.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/api-docs/gen-components-docs/markdown/index.mjs b/bin/api-docs/gen-components-docs/markdown/index.mjs index 8fd61a25fcace..5978e7e80fe26 100644 --- a/bin/api-docs/gen-components-docs/markdown/index.mjs +++ b/bin/api-docs/gen-components-docs/markdown/index.mjs @@ -8,8 +8,17 @@ import json2md from 'json2md'; */ import { generateMarkdownPropsJson } from './props.mjs'; +/** + * If the string is contentful, ensure that it ends with a single newline. + * Otherwise normalize to `undefined`. + * + * @param {string} [str] + */ function normalizeTrailingNewline( str ) { - return str?.length ? str.replace( /\n*$/, '\n' ) : undefined; + if ( ! str?.trim() ) { + return undefined; + } + return str.replace( /\n*$/, '\n' ); } export function generateMarkdownDocs( { typeDocs, subcomponentTypeDocs } ) {