textConvert
    Preparing search index...

    Function maskText

    • Partially masks a string for display purposes (e.g. showing a masked email or card number in a UI without exposing the full value).

      If neither visibleStart nor visibleEnd is given, the first 2 characters are shown by default. Specifying either one turns off that implicit default for the side you didn't specify — e.g. passing only visibleEnd hides the start entirely, rather than also showing the first 2 characters.

      Parameters

      • text: string

        Text to mask.

      • options: { maskChar?: string; visibleEnd?: number; visibleStart?: number } = {}
        • OptionalmaskChar?: string

          Character(s) to use for masked positions. Default is '*'.

        • OptionalvisibleEnd?: number

          Number of characters to leave visible at the end.

        • OptionalvisibleStart?: number

          Number of characters to leave visible at the start.

      Returns string

      The masked string, or the original string unchanged if the requested visible portions cover the whole string.

      maskText('jordan@example.com'); // 'jo****************'
      maskText('4111111111111234', { visibleEnd: 4 }); // '************1234'
      maskText('secret-token-value', { visibleStart: 0, visibleEnd: 0, maskChar: '#' }); // '##################'