textConvert
    Preparing search index...

    Function sanitize

    • Runs text through a configurable pipeline of existing textConvert functions -- trimming, whitespace normalization, PII/secret redaction, and HTML escaping -- for the common "clean this user input/log line before it's stored or displayed" case.

      This is composition, not new detection logic: every step just calls the same underlying function (normalizeWhitespace, redact, escapeHtml) that already exists standalone, in a fixed order regardless of the order options are given in: trim -> normalizeWhitespace -> redactPII -> escapeHtml.

      Redaction deliberately runs on the raw, unescaped text -- so pattern matching isn't affected by HTML-escaped characters -- and escaping always runs last, so the final output is safe to render no matter which other steps ran.

      Parameters

      • text: string

        Text to sanitize.

      • options: SanitizeOptions = {}

        Which steps to run. Every step defaults to off -- sanitize(text) with no options returns text unchanged (aside from the shared invalid-input check).

      Returns string

      The sanitized text.

      sanitize('  Contact jordan@example.com <b>now</b>  ', {
      trim: true,
      redactPII: true,
      escapeHtml: true,
      });
      // 'Contact jo**************** &lt;b&gt;now&lt;/b&gt;'