fabian-hiller / decode-formdata

Decodes complex FormData into a JavaScript object
MIT License
241 stars 7 forks source link

URLSearchParams #13

Open jamiebuilds opened 5 months ago

jamiebuilds commented 5 months ago

The current name is a bit unfortunate for this, but it would be nice if this library was generic over both FormData and URLSearchParams so you could do this:

let url = new URL("https://example.com?items.0=foo&items.1=bar")
let values = decode(url.searchParams)
// { items: ["foo", "bar"] }

You may then also want to support some more of the syntaxes commonly used in search params. See https://www.npmjs.com/package/qs for some examples

fabian-hiller commented 5 months ago

Thank you for creating this issue. This is already on my todo list, but it will probably be a while before I find the time to work on it, as I am currently focused on Valibot.

sacrosanctic commented 2 weeks ago

@fabian-hiller

I am actually already using this for both searchParams and formData, its a bit of a hack at the moment where I convert searchParams into formData with a for loop.

If you can point me in the right direction, can create a PR with a provide implementation of it

fabian-hiller commented 2 weeks ago

We should probably work on a native decode-params library with a similar API and implementation as decode-formdate. We can work together if you are interested.