43081j / picoquery

A small library for parsing and serializing query strings
MIT License
69 stars 2 forks source link

feat: presets #52

Open reslear opened 4 weeks ago

reslear commented 4 weeks ago

maybe initialise defaults options like presets:

for example default keep same now:

stringify({ foo: [ { }, 2 ]}, { preset: 'default' })
// populate.author.fields.0=firstName&populate.author.fields.1=lastName

or with preset:

stringify('foo.bar=baz', { preset: 'qs' })
// populate%5Bauthor%5D%5Bfields%5D%5B0%5D=firstName&populate%5Bauthor%5D%5Bfields%5D%5B1%5D=lastName

https://github.com/ljharb/qs/blob/60b62546ad05d436b64b2e0feafc7a5cf4727aee/lib/stringify.js#L30

roughly similar merge with default:

{
  nestingSyntax: 'index',
}

I think it has increased users, like for me strapi users who have to use qs but don't want to.

43081j commented 4 weeks ago

i was also wondering about this, good idea i think

codemods currently have to migrate by repeating a set of default options to be "qs-like"

i'd be open to contributions for this. im not sure if it should be preset though, maybe compat: 'qs' or something. as i don't want to end up with us having to maintain a list of presets