Last active
August 28, 2020 16:19
-
-
Save avrcoelho/246f1255392f86e7b6d667a724f99aac to your computer and use it in GitHub Desktop.
Mask for string
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
| const mask = (value, pattern) => { | |
| let index = 0; | |
| const string = value.toString(); | |
| return pattern.replace(/#/g, () => string[index++] || ''); | |
| } | |
| mask('1145820412', '(##) ####-####') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment