Last active
December 18, 2021 11:46
-
-
Save c7x43t/8ddcdf35155765f6a09e6d492e641d1b 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 getUrlQueryParams(url){ | |
return Object.fromEntries((new URLSearchParams(new URL(url).search))); | |
} |
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
String.prototype.getURLSearchParams = function(){return new URLSearchParams(String(this))} | |
URLSearchParams.prototype.toObject = function(){return this.entries().fromEntries()} | |
Object.getPrototypeOf(new URL(location.href).search.getURLSearchParams().entries()).fromEntries = function(){return Object.fromEntries(this)} | |
//usage: | |
new URL(url).search.getURLSearchParams().toObject() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment