Open mehdihaddad opened 3 years ago
@mehdihaddad Nice catch !! My approach for this is to
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
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.
Hello, would it be possible to fix this?
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?
Closing this for now. If someone can demonstrate that this would be a useful feature to have, I'll reopen the issue.
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?
@iSplasher reopening because there seems to be demand for this feature.
For exemple,
OUTPUT: http://myurl.com?myparams=1?foo=2&bar=2
WANTED: http://myurl.com?myparams=1&foo=2&bar=2