Skip to content

skipNulls option for queryString.stringify #196

@goodwin64

Description

@goodwin64

Hi!

I am now comparing 2 libs for future use on my project: qs and query-string.
The second one has some advantages like encoding/decoding booleans and numbers which are important for me. But the 1st one has skipNulls option which allows to skip null and undefined values:

const obj1 = {
  a: 1,
  b: '2',
  c: [3, 4, 5],
  d: true,
  e: 'just string',
  f: null,
  g: undefined,
};

// qs
// can skip null/undefined values
const ex2 = qs.stringify(obj1, {
  addQueryPrefix: true,
  arrayFormat: 'comma',
  skipNulls: true,
});
const ex3 = qs.parse(ex2, {
  parseArrays: true,
  comma: true,
  ignoreQueryPrefix: true,
});

// query-string
// can store numbers and booleans
const ex4 = queryString.stringify(obj1, {
  strict: true,
});
const ex5 = queryString.parse(ex4, {
  parseNumbers: true,
  parseBooleans: true,
});

console.log('ex2', ex2);
console.log('ex3', ex3);
console.log('ex4', ex4);
console.log('ex5', ex5);

Screenshot from 2019-07-26 10-48-56

Does it sound reasonable to implement this option?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions