43081j / picoquery

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

Omit undefined values from query #46

Closed minht11 closed 3 months ago

minht11 commented 4 months ago

I am using qs library and it seems to omit query entirely when its' value is undefined.

import * as qs from 'qs';
import * as pico from 'picoquery';

const data = {
  publicationState: undefined,
};

const query = qs.stringify(data, {
  encodeValuesOnly: true,
});

const newQuery = pico.stringify(data, {
  nestingSyntax: 'index',
});

console.log(query);
console.log(newQuery);

Result: QS: ` Picoquery:publicationState=`

Reproduction

43081j commented 4 months ago

Makes sense to me. Should be an easy fix if you want to contribute

43081j commented 3 months ago

Fixed in #51