`skipNulls` option for queryString.stringify
See original GitHub issueHi!
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);
Does it sound reasonable to implement this option?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Remove keys with empty or null values in qs.stringify when ...
qs package added skipNulls option since v5.1.0. To completely skip rendering keys with null values, use the skipNulls flag:.
Read more >query-string - npm.io
Extract a query string from a URL that can be passed into .parse() . Note: This behaviour can be changed with the skipNull...
Read more >Node.js Query String - eduCBA
guide to Node.js Query String. Here we discuss the introduction to Node.js Query String,along with working and js query string methods respectively.
Read more >Query string | Node.js v19.3.0 Documentation
The querystring.encode() function is an alias for querystring.stringify() . ... if necessary by assigning querystring.escape to an alternative function.
Read more >query-string@7.1.3 - jsDocs.io
Overview. Parse and stringify URL query strings ... Note: This behaviour can be changed with the skipNull option.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
3 separate configurable options would be very nice inspired by https://www.npmjs.com/package/qs.
I think the option should be
skipNullAndUndefined
to make it clear what it does.