Skip to content

Instantly share code, notes, and snippets.

@ArrayIterator
Created April 9, 2018 13:54
Show Gist options
  • Save ArrayIterator/2019fbf431d937d8b30e50f6b1cc21e2 to your computer and use it in GitHub Desktop.
Save ArrayIterator/2019fbf431d937d8b30e50f6b1cc21e2 to your computer and use it in GitHub Desktop.
var sanityHTMLClass = (str) => {
if (typeof str !== 'string') {
return '';
}
return str
// replace for v?s?printf
.replace(/%[a-fA-F0-9][a-fA-F0-9]/, '')
// Limit to A-Z,a-z,0-9,_,-
.replace(/[^A-Za-z0-9_-]/, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment