Skip to content

Commit

Permalink
Added documentation for the new strictNullHandling flag
Browse files Browse the repository at this point in the history
  • Loading branch information
scharf committed May 21, 2015
1 parent f48ea7e commit 2d85072
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,35 @@ The delimiter may be overridden with stringify as well:
Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' });
// 'a=b;c=d'
```

### Handling of `null` values

By default, `null` values are treated like empty strings:

```javascript
Qs.stringify({ a: null, b: '' });
// 'a=&b='
```

Parsing does not distinguish between parameters with and without equal signs. Both are converted to empty strings.

```javascript
Qs.parse('a&b=')
// { a: '', b: '' }
```

To distinguish between `null` values and empty strings use the `strictNullHandling` flag. In the result string the `null`
values have no `=` sign:

```javascript
Qs.stringify({ a: null, b: '' }, { strictNullHandling: true });
// 'a&b='
```

To parse values without `=` back to `null` use the `strictNullHandling` flag:

```javascript
Qs.parse('a&b=', { strictNullHandling: true });
// { a: null, b: '' }

```

0 comments on commit 2d85072

Please sign in to comment.