Created
January 30, 2012 18:24
-
-
Save zachstronaut/1705796 to your computer and use it in GitHub Desktop.
An HTMLSAFE and SLUGIFY in JavaScript
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
/** | |
* SLUGIFY - Attempts to match Django slugify filter: "Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace." | |
*/ | |
function SLUGIFY(str) { | |
return str.toString().toLowerCase().replace(/^\s+|\s+$/g,'').replace(/\s/g, '-').replace(/[^-_a-z0-9]/g, ''); | |
} | |
/** | |
* HTMLSAFE - Convert &<>" to HTML entities | |
*/ | |
function HTMLSAFE(str) { | |
return str.toString().replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment