diff --git a/server/src/features/conver-message.ts b/server/src/features/conver-message.ts index 325ef57..29ce539 100644 --- a/server/src/features/conver-message.ts +++ b/server/src/features/conver-message.ts @@ -14,8 +14,19 @@ function isTextInFormat(text: string) { return dateRegex.test(date) && productCodeRegex.test(productCode); } +/** + * Chuẩn hoá text: gộp nhiều dòng trống liên tiếp thành 1 dòng trống duy nhất + */ +export function normalizeBlankLines(text: string): string { + return text.replace(/\n\s*\n+/g, '\n\n'); +} + export function formatTextIfValid(text: string) { - if (!isTextInFormat(text)) return text; // Không đúng format thì trả về nguyên bản + if (!isTextInFormat(text)) { + const newText = normalizeBlankLines(text); + + return newText; + } // Không đúng format thì trả về nguyên bản const lines = text .split('\n')