From 91c8f861df4f385908b0b0241d862813e994aa86 Mon Sep 17 00:00:00 2001 From: Ryan Wheale Date: Fri, 9 Apr 2021 14:22:19 -0600 Subject: [PATCH] docs: add note and links for coercing primitive values --- .editorconfig | 1 + README.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/.editorconfig b/.editorconfig index 91040dde..0ea91d99 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/README.md b/README.md index 09e2cc9e..0c72db3c 100644 --- a/README.md +++ b/README.md @@ -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)