-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Accept a boolean for the removeQueryParameters
option
#136
Conversation
index.js
Outdated
@@ -187,6 +187,10 @@ const normalizeUrl = (urlString, options) => { | |||
// Take advantage of many of the Node `url` normalizations | |||
urlString = urlObj.toString(); | |||
|
|||
if (options.removeQueryParameters === true) { | |||
urlString = urlString.split('?')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not safe. Instead, modify the URL object.
removeQueryParameters: false | ||
}); | ||
//=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index.d.ts and readme should be fully in sync.
readme.md
Outdated
//=> 'http://sindresorhus.com' | ||
``` | ||
|
||
`false` will not remove any query parameter. Other options like `sortQueryParameters` are still applied when toggled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see the point of:
Other options like
sortQueryParameters
are still applied when toggled.
That should already be obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it.
removeQueryParameters
boolean option - #133removeQueryParameters
option
Thanks for the feedback. PR has been updated! |
index.js
Outdated
@@ -173,6 +173,12 @@ const normalizeUrl = (urlString, options) => { | |||
} | |||
} | |||
|
|||
if (options.removeQueryParameters === true) { | |||
for (const key of [...urlObj.searchParams.keys()]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just set urlObj.search = '';
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't knew that. Changed it.
Everything is not resolved. |
Should all be resolved now. |
You still need to do https://github.com/sindresorhus/normalize-url/pull/136/files#r654795467 |
Should be fully in sync now. |
I saw issue #133 as unresolved so I went ahead and gave it a go.
removeQueryParameters
boolean flag and implemented the new behaviorAny feedback is welcome.
Fixes #133