qs icon indicating copy to clipboard operation
qs copied to clipboard

Custom stringify arrays and objects

Open leninlin opened this issue 4 years ago • 3 comments

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 avatar May 02 '20 12:05 leninlin

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 avatar May 02 '20 22:05 leninlin

Maybe something like that?

leninlin avatar May 03 '20 00:05 leninlin

@leninlin are you still interested in completing this PR?

ljharb avatar Jan 13 '21 16:01 ljharb