Skip to content

Instantly share code, notes, and snippets.

@kessejones
Last active September 16, 2019 12:30
Show Gist options
  • Save kessejones/0ee6d9906b68406350436dbdfd2c479e to your computer and use it in GitHub Desktop.
Save kessejones/0ee6d9906b68406350436dbdfd2c479e to your computer and use it in GitHub Desktop.
Text Mask
function mask(value, mask){
let i = 0;
let v = value.toString();
const removeChar = mask.split('').filter(function(item){
return item != '#';
});
for(const a of removeChar){
v = v.replace(a, '')
}
if(v.length = mask.length)
return value;
return mask.replace(/\#/g, () => v[i++] || '')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment