-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
Suggest standard URLSearchParams alternative in README #307
Comments
I agree. I've been thinking about this. I don't think it's useful to just link to it though. We should explain in detail how it differs and their trade-offs. |
I recently wrote an article detailing the differences between https://dev.to/nerdyman/replacing-query-string-with-native-urlsearchparams-4kdg Edit: There's also a CodeSandbox demo https://tflmb.csb.app/ |
It's been a year. Maybe it would help to point to this issue in the README and leave it up to the developer to decide if they want to use the standard object? This module is extremely popular. Given that, many devs may automatically use this module without even knowing there's a built-in alternative. I've been doing web dev for 10+ years and had no idea either. Was just about to install this module when I randomly found some reference to The even more popular querystring package deprecated itself in favor of URLSearchParams. |
A bonus point for using URLSearchParams instead is that the fetch api and some other http libs will automatically insert the correct content-type header automatically when using URLSearchParams as a body... something that the dev article don't mention |
Thanks I have merged the documentation update 😊 |
Note: It's not a compatible replacement as space is stringified differently. > (await import("query-string")).stringify({"foo bar": "bar foo"})
'foo%20bar=bar%20foo'
> String(new URLSearchParams({"foo bar": "bar foo"}))
'foo+bar=bar+foo' The > encodeURIComponent(" ")
'%20' So it's certainly not without pitfalls to switch to |
The URL standard includes the
URLSearchParams
interface which in many cases should be able to replace this module. I think it should be suggested as an alternative.The text was updated successfully, but these errors were encountered: