Created
December 20, 2018 10:59
-
-
Save gukandrew/04e18deaa7b3318832ff0873a2a58c6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Create a Mask for an email address using ES6 syntax | |
Could be used for confirmation of email address or preventing to public expose of address | |
Author: Andrew Guk https://gist.github.com/gukandrew | |
*/ | |
function emailMask(email, mask = '*') { | |
let masked = ''; | |
let prev; | |
masked = [...email].map((char, index) => { | |
const isFirstChar = index == 0; | |
const isSpecial = char == '.' || char == '@'; | |
const isAfterSpecial = prev == '.' || prev == '@'; | |
const umask = (isFirstChar || isSpecial || isAfterSpecial) ? char : null; | |
prev = char; | |
return umask || mask; | |
}); | |
return masked.join(''); | |
} | |
// Usage: | |
// console.log(emailMask('[email protected]', '*')); | |
// Output: m*.o**.e****@m*******.c** |
IvanAdmaers
commented
Sep 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment