-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Add support for arrayFormat: 'bracket-separator'
#276
Conversation
I think dropping the |
You need to explicitly document the behavior with empty array, null in array, and empty string in array in the docs. |
arrayFormat: 'bracket-separator'
I would also like to see more tests. |
And sorry for the slow reply. I've just been overwhelmed with notifications. |
I believe I've covered all that was asked. Please let me know if something else needs attention. |
Bump |
Still have eyes on this, just haven't had a second to address. I will fix this up soon |
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Review comments have been addressed. Thank you for your patience. |
Can you fix the merge conflict? |
Merge conflicts resolved. |
The idea behind this format is to gain the advantages of short query strings that you have with
comma
andseparator
formats while marking a field as explicitly an array via a postfixed[]
syntax.There are still are 2 question in regards to implementation:
What should happen for
{foo: []}
? Currently, it would drop the parameter from the stringified query which is the same as{foo: null}
This is undesirable personally. I feel like
{foo: []}
should produce?foo[]
unless I specify a flag to drop it.This would be a deviation from the
?bar&biz
that non-arrays get the treatment of when they are null (no trailing=
), but I feel like it makes sense as we have enough information to say, explicitly, that this is an array. Whereas if it were{foo: null}
we don't know, explicitly, that this is an array, so it would produce?foo
which would mean that it would roundtrip correctly.However, the only way to produce this would be to change how the system is using Array.prototype.reduce as the reducer function is not ever invoked when the array is empty.
What should happen for
{foo: ['one', null, 'three']}
. Currently it will drop the null and producefoo[]=one,three
I haven't a strong opinion on this as it matches the functionality ofseparator
. The only deviation from theseparator
functionality in regards to value dropping is thatbracket-separator
does not drop empty strings.[Edit]: This has been changed to follow the
skipNull
andskipEmptyString
options. As such, by default,null
and''
will not be dropped. See #304 for details.Thus, the following are true:
{foo: ['one', '', null, 'four']}
foo[]=one,,,four
{foo: ['one', '', null, 'four']}
skipNull: true
foo[]=one,,four
{foo: ['one', '', null, 'four']}
skipEmptyString true
foo[]=one,,four
{foo: ['one', '', null, 'four']}
skipEmptyString true, skipNull: true
foo[]=one,four