Skip to content

Instantly share code, notes, and snippets.

@petja
Created August 23, 2024 12:27
Show Gist options
  • Save petja/3ff1f26569ee2018370015daf758429e to your computer and use it in GitHub Desktop.
Save petja/3ff1f26569ee2018370015daf758429e to your computer and use it in GitHub Desktop.
function maskLine(text: string) {
const len = text.length;
const first = text.substring(0, 1);
const first2 = text.substring(0, 2);
const last = text.substring(len - 1);
if (len < 2) return text;
if (len === 2) return first + '•';
if (len === 3) return first + '••';
return first2 + '•'.repeat(len - 3) + last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment