Skip to content

obfuscateText

A util for masking sensitive information that needs to be hidden, that is also used by the ObfuscateText component.

Note: this is intended to be used in situations where the ObfuscateText component cannot be used; for instance, as part of an input value.

Import

ts
import obfuscateText from '@leaflink/stash/utils/obfuscateText';

Usage

Provide a string to obfuscate

ts
obfuscateText('foobar');

Returns:

ts
> '••••••••••'

Options

maskChar

Customize the character used for masking. Default:

ts
obfuscateText('foobar', { maskChar: '*' });

Returns:

ts
> '**********'

maskCharCount

Customize the number of masking chars to include. Default: 10

ts
obfuscateText('foobar', { maskCharCount: '2' });

Returns:

ts
> '••'

lengthToKeep

Sets the number of characters not to mask. Default: 0

ts
obfuscateText('foobar', { lengthToKeep: '4' });

Returns:

ts
> '••••••••••obar'

position

Set which side of the string to mask. Default: start

To be used in conjunction with lengthToKeep, otherwise it won't have any effect.

Options: start, end

ts
obfuscateText('foobar', { lengthToKeep: '4', position: 'end' });

Returns:

ts
> 'foob••••••••••'

Playground

Visit the <ObfuscateText /> component to interact with the underlying string masking behavior.