Skip to content

Instantly share code, notes, and snippets.

@qwtel
Last active November 20, 2019 20:35
Show Gist options
  • Save qwtel/2ca6a0cc80e64075389a5324cb1ad755 to your computer and use it in GitHub Desktop.
Save qwtel/2ca6a0cc80e64075389a5324cb1ad755 to your computer and use it in GitHub Desktop.
export class ParamsURL extends URL {
constructor(href, params, origin = globalThis.location) {
super(href, origin);
if (params) {
this.search = new URLSearchParams([...this.searchParams, ...Object.entries(params)]);
}
}
}
@qwtel
Copy link
Author

qwtel commented Nov 20, 2019

Usage:

new ParamsURL('/', { foo: 'bar' }).href
// => "https://gist.github.com/?foo=bar"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment