maskString
Masks part of a string by replacing characters with a mask character.
Syntax
typescript
maskString(str: string, mask: string, maskStart: number, maskLength: number): stringParameters
| Parameter | Type | Description |
|---|---|---|
str | string | The original string. |
mask | string | The mask character or string. |
maskStart | number | Starting index to apply the mask (>= 0). |
maskLength | number | Number of characters to be masked (>= 0). |
Returns
| Type | Description |
|---|---|
string | The resulting string with the masked part. |
Example
typescript
maskString("123456789", "*", 2, 4); // "12****789"
maskString("abcdef", "#", 0, 3); // "###def"
maskString("openai", "X", 4, 10); // "openXX"Notes
- Throws
TypeErrorif the arguments are not of the expected type. - Throws
RangeErrorifmaskStartormaskLengthare negative, or ifmaskStartis greater than the string length. - If
maskLengthexceeds the remaining length of the string, masks until the end.
