-
-
Notifications
You must be signed in to change notification settings - Fork 453
Closed
Labels
Description
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);