Last active
April 22, 2021 16:00
-
-
Save dwsmart/dcaa0847533d2e85b535e5cf55fe597b to your computer and use it in GitHub Desktop.
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 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