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

Add params to an url who already have params #151

Open
mehdihaddad opened this issue Mar 15, 2021 · 8 comments · May be fixed by #258
Open

Add params to an url who already have params #151

mehdihaddad opened this issue Mar 15, 2021 · 8 comments · May be fixed by #258
Labels
enhancement New feature or request

Comments

@mehdihaddad
Copy link

For exemple,

const url = 'http://myurl.com?myparams=1'
urlcat(url, {foo: 2, bar: 3})

OUTPUT: http://myurl.com?myparams=1?foo=2&bar=2
WANTED: http://myurl.com?myparams=1&foo=2&bar=2

@harshilparmar
Copy link
Contributor

@mehdihaddad Nice catch !!
My approach for this is to

  1. Check ? with regex
  2. Append next params after that
    @balazsbotond What you say !! I would like to take this 😀

@mehdihaddad
Copy link
Author

To check :

var objURL = new URL(url)
if(objURL.search.length > 1) {
   // Yes, i already have queryParams
} else {
  // Nope !
}

.search give you only the queryParams string like http://myurl.com?foo=bar -> ?foo=bar

@mehdihaddad
Copy link
Author

To check :

var objURL = new URL(url)
if(objURL.search.length > 1) {
   // Yes, i already have queryParams
} else {
  // Nope !
}

.search give you only the queryParams string like http://myurl.com?foo=bar -> ?foo=bar

Maybe a regex would be better, because of url value. In urlcat you can have urlcat('test/test', {....}) and new URL('test/test') will gave you an error.

@iSplasher
Copy link

Hello, would it be possible to fix this?

@balazsbotond
Copy link
Owner

Thanks for reporting this, @mehdihaddad. Could you please show me a realistic use case where this:

const url = 'http://myurl.com'
urlcat(url, {foo: 2, bar: 3, myparams: 1})

wouldn't solve the problem?

@balazsbotond
Copy link
Owner

Closing this for now. If someone can demonstrate that this would be a useful feature to have, I'll reopen the issue.

@iSplasher
Copy link

iSplasher commented Nov 20, 2022

A realistic use case is when you just want to ensure a url, which may already have query params, contains a specific set of params, like the first post demonstrated.
If this is not going to be supported then could you please point it out in the readme?

@balazsbotond balazsbotond added the enhancement New feature or request label Dec 5, 2022
@balazsbotond
Copy link
Owner

@iSplasher reopening because there seems to be demand for this feature.

@balazsbotond balazsbotond reopened this Dec 5, 2022
jrel added a commit to jrel/urlcat that referenced this issue May 22, 2023
FIX: Add params to an url who already have params balazsbotond#151
@jrel jrel linked a pull request May 22, 2023 that will close this issue
jrel added a commit to jrel/urlcat that referenced this issue May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants