Created
August 16, 2019 23:08
-
-
Save stamat/830ab252b506b48797a230bd2f90eaf1 to your computer and use it in GitHub Desktop.
Wordpress like simple sanitize_title for javascript. Not checking for accents, since it is a slow process.
This file contains 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
if (!String.prototype.trim) { | |
String.prototype.trim = function () { | |
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | |
}; | |
} | |
function slug(s) { | |
s = s.toLowerCase().trim(); | |
s = s.replace(/[^a-z0-9\s_-]/ig, ''); | |
return s.replace(/[\s\uFEFF\xA0]+/ig, '-'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment