whatwg/url

Proposal: Functional chaining on URLSearchParams

JamiesonRoberts opened this issue · 3 comments

It would be good to allow functional chaining of methods on URLSearchParams

Today to chain operations like sort() and toString() we have to do the following

const url = new URLSearchParams('?b=23&c=12&a=asdf');
url.sort();
console.log(url.toString());

The ideal state would be to be able to do the following in various scenarios:

console.log(new URLSearchParams('?b=23&c=12&a=asdf').sort().toString());

-- or --

const url = new URLSearchParams('?b=23&c=12&a=asdf');
console.log(url.sort().toString());

This came up in #90 before. I'm personally not convinced this is a good idea. If we ever wanted sort() to indicate how many mutations it made for instance that would no longer be possible.

@annevk interesting, I hadn't thought about that. What are the possible use cases for listing mutations of something like a sort? Also, aren't there other prototypes that do that with a map like syntax where you then consume it with multiple parameters?