update view message

This commit is contained in:
Admin 2025-09-12 14:42:39 +07:00
parent 279e1a1785
commit 45c2093d05
1 changed files with 12 additions and 1 deletions

View File

@ -14,8 +14,19 @@ function isTextInFormat(text: string) {
return dateRegex.test(date) && productCodeRegex.test(productCode); 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) { 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 const lines = text
.split('\n') .split('\n')