Skip to content

parse single value as array #434

@JoseVSeb

Description

@JoseVSeb

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions