Last active
September 9, 2016 11:48
-
-
Save axe312ger/be7ba49f6171703dadbcaf8273a8c99d to your computer and use it in GitHub Desktop.
Human readable encodeURIComponent results since utf-8 is widely supported yet.
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
const reserved = [ | |
':', '/', '?', '#', '[', ']', '@', // RFC 3986 gen-delims | |
'!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=', // RFC 3986 sub-delims | |
'%' // % needs to be encoded to ensure proper decoding | |
] | |
function utf8EncodeURIComponent (uri) { | |
return Array.from(uri) | |
.map((char) => reserved.includes(char) ? encodeURIComponent(char) : char) | |
.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment