-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Feature request: option for deciding how to parse query without argument #223
Comments
I'm not sure what you mean by "without arguments" - in You can certainly do this, however: qs.stringify({ foo: '', bar: null }, { strictNullHandling: true }); // 'foo&bar='
qs.parse('foo&bar=', { strictNullHandling: true }); // { bar: '', foo: null } Does that cover your use case? |
"Query string field without a value" would probably be more accurate, sorry. I was mainly wondering if something like this were possible -- basically, supporting valueless fields being parsed as having a given value: qs.parse('foo&bar=', { parseEmptyValueAs: true }); // { bar: '', foo: true }
// possibly also useful
qs.parse('foo&bar=', { parseEmptyValueAs: '123' }); // { bar: '', foo: '123' } Thanks! |
That's interesting. Effectively, it'd be an option for both parse and stringify that defined what primitive "an absent value" was - so I think that's reasonable, since it's pretty cumbersome to do that otherwise. |
Sounds good, do you think it would make sense to (eventually) combine with |
yeah, i'd think that the options would be incompatible - ie, |
Addresses ljharb#223. Behavior: * When parsing and encountering empty values, replaces them with opt.emptyValue (default to '') * When stringifying and encountering value === opt.emptyValue, outputs a key without a value
Hi @ljharb I've pushed up a WIP patchset, ran into a small issue and was hoping to get your feedback. Thanks! |
Addresses ljharb#223. Behavior: * When parsing and encountering empty values, replaces them with opt.emptyValue (default to '') * When stringifying and encountering value === opt.emptyValue, outputs a key without a value
Addresses ljharb#223. Behavior: * When parsing and encountering empty values, replaces them with opt.emptyValue (default to '') * When stringifying and encountering value === opt.emptyValue, outputs a key without a value
Hi,
I was wondering if it would be possible to support passing an option for deciding how to parse queries without arguments? Currently
url?foo
can be parsed as either the empty string or asnull
. I am wondering if it's possible to have the parser treat a query without arguments astrue
.Some background: I ran into a case in our codebase which does this, it seemed odd to me but apparently there's nothing in the standards that forbid queries without arguments. Are there more specific standards (e.g. the node implementation) that this library is trying to adhere to?
Thanks!
The text was updated successfully, but these errors were encountered: