parse single value as array
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (8 by maintainers)
Top GitHub Comments
Went ahead and published v6.10.4.
@ljharb It does! Thanks so much!