@peopl-health/nexus 3.1.4 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/outputSanitizer.js +28 -2
- package/package.json +1 -1
|
@@ -7,17 +7,43 @@ function removeBracketContent(text) {
|
|
|
7
7
|
return text.replace(/\[([^\]]*)\]/g, '').trim();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function formatForWhatsApp(text) {
|
|
11
|
+
if (!text || typeof text !== 'string') return text;
|
|
12
|
+
|
|
13
|
+
let formatted = text;
|
|
14
|
+
|
|
15
|
+
// Add line breaks after dash items (bullet points)
|
|
16
|
+
formatted = formatted.replace(/(\.\s*-\s+)/g, '.\n\n- ');
|
|
17
|
+
formatted = formatted.replace(/(:)\s*(-\s+)/g, '$1\n- ');
|
|
18
|
+
|
|
19
|
+
// Add line breaks after semicolons when they separate items
|
|
20
|
+
formatted = formatted.replace(/;\s*-\s+/g, ';\n- ');
|
|
21
|
+
|
|
22
|
+
// Add line breaks after periods that end sentences before dashes
|
|
23
|
+
formatted = formatted.replace(/(\.\s+)(-\s+)/g, '$1\n$2');
|
|
24
|
+
|
|
25
|
+
// Convert dashes to bullet points
|
|
26
|
+
formatted = formatted.replace(/^-\s+/gm, '• ');
|
|
27
|
+
formatted = formatted.replace(/(\n|^)\s*-\s+/g, '$1• ');
|
|
28
|
+
|
|
29
|
+
// Clean up multiple consecutive line breaks
|
|
30
|
+
formatted = formatted.replace(/\n{3,}/g, '\n\n');
|
|
31
|
+
|
|
32
|
+
return formatted.trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
10
35
|
function sanitizeOutput(text) {
|
|
11
36
|
if (!text || typeof text !== 'string') return text;
|
|
12
37
|
|
|
13
38
|
let sanitized = text;
|
|
14
39
|
sanitized = removeBracketContent(sanitized);
|
|
15
|
-
sanitized = sanitized
|
|
40
|
+
sanitized = formatForWhatsApp(sanitized);
|
|
16
41
|
|
|
17
42
|
return sanitized;
|
|
18
43
|
}
|
|
19
44
|
|
|
20
45
|
module.exports = {
|
|
21
46
|
sanitizeOutput,
|
|
22
|
-
removeBracketContent
|
|
47
|
+
removeBracketContent,
|
|
48
|
+
formatForWhatsApp
|
|
23
49
|
};
|