MCPcopy Create free account
hub / github.com/PromtEngineer/localGPT / normalizeWhitespace

Function normalizeWhitespace

src/utils/textNormalization.ts:6–24  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

4 */
5
6export function normalizeWhitespace(text: string): string {
7 if (!text || typeof text !== 'string') {
8 return '';
9 }
10
11 text = text.replace(/\n{3,}/g, '\n\n');
12
13 text = text.replace(/[ \t]+$/gm, '');
14
15 text = text.replace(/[ \t]{3,}/g, ' ');
16
17 text = text.replace(/[ \t]*\n[ \t]*\n[ \t]*\n/g, '\n\n');
18
19 text = text.replace(/[ \t]+\n/g, '\n');
20
21 text = text.trim();
22
23 return text;
24}
25
26/**
27 * Specialized normalization for streaming tokens to prevent accumulation

Callers 4

ThinkingTextFunction · 0.90
StructuredMessageBlockFunction · 0.90
ConversationPageFunction · 0.90
normalizeStreamingTokenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected