Mask Sensitive Information
Masks parts of a sensitive string, like a credit card or email address.
- string
- mask
- sensitive
Install
npx shadcn@latest add https://quicksnip.dev/r/mask-sensitive-information.jsonThis snippet is not verified yet. Review it before use, or help verify it.
Code
function maskSensitiveInfo(str, visibleCount = 4, maskChar = '*') {
return str.slice(0, visibleCount) + maskChar.repeat(Math.max(0, str.length - visibleCount));
}Usage
maskSensitiveInfo('123456789', 4); // Returns: '1234*****'
maskSensitiveInfo('example@mail.com', 2, '#'); // Returns: 'ex#############'