Skip to content

Instantly share code, notes, and snippets.

@avrcoelho
Last active August 28, 2020 16:19
Show Gist options
  • Select an option

  • Save avrcoelho/246f1255392f86e7b6d667a724f99aac to your computer and use it in GitHub Desktop.

Select an option

Save avrcoelho/246f1255392f86e7b6d667a724f99aac to your computer and use it in GitHub Desktop.
Mask for string
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