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

Query param with an empty value #384

Closed
AlekseyLeshko opened this issue Aug 6, 2019 · 1 comment
Closed

Query param with an empty value #384

AlekseyLeshko opened this issue Aug 6, 2019 · 1 comment
Labels

Comments

@AlekseyLeshko
Copy link
Contributor

Thanks for the awesome library!

Sometimes I need to add a query, but I don’t know if exists value.
For example

const epicUrlBuilder = (foo, bar) => URI().addQuery('foo', foo).addQuery('bar', bar)
epicUrlBuilder(42).query() === "foo=42&bar" // not cool
epicUrlBuilder(42).query() === "foo=42" // it’s cool

Yes, of course, I could implement a custom function with this logic.
I think it would be cool if this feature was included in the library.

Maybe update readable or create a new method?

What are you thinking about it?

@rodneyrehm
Copy link
Member

Hey there,

sorry for the late reply.

The docs show the following example:

uri.addSearch("no-value");

which is technically the same as

uri.addSearch("no-value", undefined);

and therefore the defined behavior of that function.

addSearch() accepts an object, which in your case could be used to rewrite epicUrlBuilder() so that it only adds values that are not undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants