Skip to content

Instantly share code, notes, and snippets.

@axe312ger
Last active September 9, 2016 11:48
Show Gist options
  • Save axe312ger/be7ba49f6171703dadbcaf8273a8c99d to your computer and use it in GitHub Desktop.
Save axe312ger/be7ba49f6171703dadbcaf8273a8c99d to your computer and use it in GitHub Desktop.
Human readable encodeURIComponent results since utf-8 is widely supported yet.
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