MCPcopy
hub / github.com/Doorman11991/smallcode / stripAnsi

Function stripAnsi

src/security/sanitize.js:219–226  ·  view source on GitHub ↗

* Strip ALL ANSI escape sequences and C1 control bytes from a string. * Preserves printable text and ordinary whitespace (tab, newline).

(input)

Source from the content-addressed store, hash-verified

217 * Preserves printable text and ordinary whitespace (tab, newline).
218 */
219function stripAnsi(input) {
220 if (typeof input !== 'string' || input.length === 0) return input;
221 let out = input;
222 for (const re of ANSI_RE) out = out.replace(re, '');
223 // Also strip raw NUL and other non-tab/newline C0 controls
224 out = out.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '');
225 return out;
226}
227
228/**
229 * Sanitize a tool result string before adding it to model context:

Callers 1

sanitizeToolOutputFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected