Created
July 9, 2015 09:20
-
-
Save e7d/a4b70e77aa7842eba7a8 to your computer and use it in GitHub Desktop.
Crypt URI with JavaScript
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() { | |
String.prototype.asciiEncode = function() { | |
var i, result = []; | |
for (i = 0; i < this.length; i++) { | |
result.push("%", this.charCodeAt(i).toString(16)); | |
} | |
return result.join(''); | |
} | |
String.prototype.cryptUri = function() { | |
return this.replace(/((?![\w]+:\/\/)[\w\.-]+)/g, function(match) { | |
return match.asciiEncode(); | |
}); | |
}; | |
})(); | |
"https://e7d.io/".cryptUri(); // https://%65%37%64%2e%69%6f/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment