Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLSearchParams.appendAll(iterable) #461

Open
ethanresnick opened this issue Dec 27, 2019 · 8 comments
Open

URLSearchParams.appendAll(iterable) #461

ethanresnick opened this issue Dec 27, 2019 · 8 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@ethanresnick
Copy link

This is a feature request for the functionality mentioned in the title. (Hopefully this is the right place for such requests.) Basically, it'd be really nice to be able to merge a bunch of items into a URL's existing query string, without having to do an explicit loop and call append on each iteration, hence something like:

const newParams = { a: true, b: false };
const url = new URL(inputUrl);
url.serachParams.appendAll(Object.entries(newParams));
@annevk annevk added addition/proposal New features or enhancements topic: api needs implementer interest Moving the issue forward requires implementers to express interest labels Jan 2, 2020
@annevk
Copy link
Member

annevk commented Jan 2, 2020

Heya, welcome! https://whatwg.org/faq#adding-new-features might be worth reading.

I'm wondering, is this a popular pattern in libraries / existing code today that makes it worth putting in the standard library? Is this often requested on Stack Overflow or equivalent forums?

@bathos
Copy link

bathos commented Feb 15, 2020

Anecdotal, @annevk, but personally I try to use the non-existent appendAll a few times a year.

(Certainly not a big nuisance that it’s absent — just surprising, I think, if one has been trained to expect symmetry from APIs like this.)

@annevk
Copy link
Member

annevk commented Feb 16, 2020

Symmetry with getAll()? Wouldn't that require a different signature from OP?

@bathos
Copy link

bathos commented Feb 16, 2020

Yes — I missed that in the OP, the method I keep imagining exists is appendAll(key, values), though I can see the utility of an entries-consuming method.

@damncodingdam
Copy link

Angular has this implemented in their HttpParams class and serves the same purpose as described in this issue. https://angular.io/api/common/http/HttpParams#appendAll

@annevk
Copy link
Member

annevk commented Mar 6, 2023

It would be nice if TC39 established some precedent here with their Map API, although I realize it's not quite the same due to duplicate keys not presenting an issue here.

(@bathos for your use case it might make sense to turn value into a rest parameter on append() and set(). Probably best as a separate issue.)

@TechAurelian2
Copy link

Anecdotal, @annevk, but personally I try to use the non-existent appendAll a few times a year.

(Certainly not a big nuisance that it’s absent — just surprising, I think, if one has been trained to expect symmetry from APIs like this.)

GitHub Copilot seems to try that too:

image

@bathos
Copy link

bathos commented Mar 14, 2023

@annevk great idea — that’s a neater solution all around for the cases I described. new issue opened: #762

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

5 participants