Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to skip keys with the value of null in .stringify() #215

Merged
merged 10 commits into from Nov 13, 2019

Conversation

yaodingyd
Copy link
Contributor

@yaodingyd yaodingyd commented Oct 6, 2019

Follow up on #197 to fix #196.

Closes #197

@yaodingyd
Copy link
Contributor Author

Additionally, fix a bug in current stringify behavior: if arrayFormat is set to comma and first item is null, the result won't have the key in it. something like

queryString.stringify({a: [null, 1, undefined, 2, null]}, {
		arrayFormat: 'comma'
	}
// => `,1,2`, missing `a=`

@sindresorhus
Copy link
Owner

What about #196 (comment) ?

index.js Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
yaodingyd and others added 2 commits October 14, 2019 11:00
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
@yaodingyd
Copy link
Contributor Author

which direction are we going? the option should be called skipNull or change the current behavior so that undefined is not skipped?

@sindresorhus
Copy link
Owner

the option should be called skipNull

This

index.d.ts Outdated
@@ -192,6 +192,26 @@ export interface StringifyOptions {
```
*/
readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;

/**
Skip the key in stringify result if value is `null` or `undefined`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it sound like it will not skip undefined by default, which it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

skipNulls option for queryString.stringify
2 participants