Skip to content

Instantly share code, notes, and snippets.

@c7x43t
Last active December 18, 2021 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7x43t/8ddcdf35155765f6a09e6d492e641d1b to your computer and use it in GitHub Desktop.
Save c7x43t/8ddcdf35155765f6a09e6d492e641d1b to your computer and use it in GitHub Desktop.
function getUrlQueryParams(url){
return Object.fromEntries((new URLSearchParams(new URL(url).search)));
}
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