ChemPal Documentation - v1.17.0
    Preparing search index...

    Function scrubText

    • Removes recognizable personal and credential data from a string: email addresses, IP addresses, URL credentials/queries/fragments, home-directory user names, authorization headers, JWTs, and token=...-style pairs.

      Parameters

      • text: string

        The text to scrub (only the first 50,000 characters are kept)

      Returns string

      The text with matches replaced by markers such as [email]

      scrubText('mail me@example.com via https://x.com/a?q=1 from /Users/jo/app.js');
      // 'mail [email] via https://x.com/a from /Users/[user]/app.js'
      export function scrubText(text: string): string {
      return text
      .slice(0, MAX_SCRUB_CHARS)
      .replace(URL_PATTERN, stripUrl)
      .replace(EMAIL, '[email]')
      .replace(SECRET_PAIR, `$1${REDACTED}`)
      .replace(AUTH_SCHEME, '$1 [token]')
      .replace(JWT, '[token]')
      .replace(IPV4, '[ip]')
      .replace(IPV6, '[ip]')
      .replace(HOME_PATH, '$1[user]');
      }