Skip to content

Commit

Permalink
docs: add note and links for coercing primitive values
Browse files Browse the repository at this point in the history
  • Loading branch information
DesignByOnyx committed Apr 9, 2021
1 parent dd0f954 commit 91c8f86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Expand Up @@ -8,6 +8,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 160
quote_type = single

[test/*]
max_line_length = off
Expand Down
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -287,6 +287,20 @@ assert.deepEqual(arraysOfObjects, { a: ['b', 'c'] })
```
(_this cannot convert nested objects, such as `a={b:1},{c:d}`_)

### Parsing primitive/scalar values (numbers, booleans, null, etc)

By default, all values are parsed as strings. This behavior will not change and is explained in [issue #91](https://github.com/ljharb/qs/issues/91).

```javascript
var primitiveValues = qs.parse('a=15&b=true&c=null');
assert.deepEqual(primitiveValues, { a: '15', b: 'true', c: 'null' });
```

If you wish to auto-convert values which look like numbers, booleans, and other values into their primitive values, you can do one of the following:

- [Install Express JS middleware to auto-convert request query parameters](https://github.com/xpepermint/query-types)
- [Copy the above MIT licensed coercion code](https://github.com/xpepermint/query-types/blob/master/index.js) directly into your project and modify it as you see fit. This code has been used on some very large projects and gives you the greatest amount of control over your data.

### Stringifying

[](#preventEval)
Expand Down

0 comments on commit 91c8f86

Please sign in to comment.