Converts a <Form>
's parameters to an object using the same logic as Rack.
This is mainly intended for testing JavaScript components that generate HTML forms to be submitted to Rails.
<form>
<input
type="hidden"
name="foo[bar][][id]"
value="1"
/>
<input
type="hidden"
name="foo[bar][][id]"
value="2"
/>
</form>
import formToRackParams from '@citizensadvice/form-to-rack-params';
const form = document.querySelector('form');
formToRakeParams(form);
/* =>
foo: {
bar: [
{ id: '1' },
{ id: '2' },
],
}
*/