Skip to content

Instantly share code, notes, and snippets.

@dwsmart
Last active April 22, 2021 16:00
Show Gist options
  • Save dwsmart/dcaa0847533d2e85b535e5cf55fe597b to your computer and use it in GitHub Desktop.
Save dwsmart/dcaa0847533d2e85b535e5cf55fe597b to your computer and use it in GitHub Desktop.
function normEncoding(string) {
try {
return urlEncodeCaseCorrect(encodeURI(path).replace(/%25/g, '%'));
} catch (e) {
return string;
}
}
function urlEncodeCaseCorrect(string) {
return path.replace(/%[0-9a-fA-F]{2}/g, function(match) {
return match.toUpperCase();
});
}
// edit - usage
console.log(normaliseEncoding('💩')) // returns %F0%9F%92%A9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment