Last active
December 16, 2015 08:49
-
-
Save onel0p3z/5408960 to your computer and use it in GitHub Desktop.
Simple HTML encoding for JSON-like objects when used in a query string (GET) UPDATE: I just found out of escape() ... just a bit late ...
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
function htmlEscape(str) { | |
return String(str) | |
.replace(/{/g, '%7B') | |
.replace(/"/g, '%22') | |
.replace(/:/g, '%3A') | |
.replace(/}/g, '&7D') | |
.replace(/,/g, '%2C') | |
.replace(/@/g, '%40') | |
.replace(/\\/g, '') | |
.split(' ').join('+') | |
//https://coderwall.com/p/jk5f3q | |
//.toLowerCase().replace(/^\s+|\s+$/g,"").replace(/[\s]+|\t|\n|\r/g, "-"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment