-
-
Notifications
You must be signed in to change notification settings - Fork 731
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
parse single value as array #434
Comments
The proper way to ensure that is to have your query strings be Any time you want to get an array regardless, you can do I could envision a |
Hi @ljharb, bumping this thread. Like @JoseVSeb, I would like to have comma separated query string for stringifying arrays, because in my use-case, I have an array of many many items and I don't want the URL to be too long. However, for an object like Would it be possible to encode using a format like |
Another option I'm thinking about is that when Edit: some changes to these lines should suffice. |
@jerrylian-db Unfortunately the comma arrayFormat is a bit weird. However,
So, it seems like perhaps stringify, with arrayFormat comma, should be turning a single-item array into a bracket-suffixed key. Would that work for your purposes? (also @JoseVSeb) |
Yes, I think that would! Here's the behavior I'm looking for:
That way, arrays of all (non-zero) sizes can be properly encoded and decoded when |
@jerrylian-db can you confirm #441 works for you? |
@ljharb It does! Thanks so much! |
@ljharb Quick question: when will these changes be released? |
There's no release schedule or anything, but I'll likely have this out soon. |
Went ahead and published v6.10.4. |
@ljharb It seems that your PR has led to some errors. Now when I run |
hmm, that does seem wrong - but the presence of encodeValuesOnly shouldn't be relevant. I'll get a fix out. |
…licit `[]` on a single-item array Properly fixes #434
0e903c0 should cover this, it'll be out in v6.10.5 shortly. |
This ended up being reverted by default, but v6.11.0 adds a |
I was looking for a good query parser including URLSearchParams, query-string and qs.
But each is lacking a feature that at least one other has.
Say, I have a query string
"a=1"
and another"a=1,2"
.Right now, if I use a comma-separated query parser, then the output would be
{a:1}
and{a:[1,2]}
respectively.But I want my app to get an array regardless; like so
{a:[1]}
and{a:[1,2]}
respectively. Sure, I could handle that in my app itself, but in real-world scenarios, I would likely have many query params; manually handling each one is not ideal, especially for something like this that should be handled by the parser.In URLSearchParams, it's possible via getAll function instead of get, but it lacks so many other essential features like having support for comma separated parsing.
It would be great to have an option to force parse certain keys as arrays and not arrays, regardless of the default inferred format; it would be more code friendly rather than having to write exceptions for every little scenario.
The text was updated successfully, but these errors were encountered: