ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.55k stars 728 forks source link

Custom stringify arrays and objects #365

Open leninlin opened 4 years ago

leninlin commented 4 years ago

I added the ability to compile the query string using a custom function for arrays and objects.

I need this to work with the Python REST framework (https://github.com/AltSchool/dynamic-rest):

qs.stringify({
  include: [ 'name', 'age' ],
  filter: {
    'age.gte': 18
  }
});
// include[]=name&include[]=age&filter{age.gte}=18

I added a function with curly brackets to the default list, but custom functions for the future will be useful for such situations.

leninlin commented 4 years ago

Any changes to stringify would need to be mirrored in parse, so things can round trip.

I'll think about it now

I'm not yet convinced that this complexity is worth adding, but I appreciate you've made it appropriately generic.

No problems. I can use fork for myself.

leninlin commented 4 years ago

Maybe something like that?

ljharb commented 3 years ago

@leninlin are you still interested in completing this PR?