\href{https://travis-ci.org/ljharb/qs}{\texttt{ }} \href{https://david-dm.org/ljharb/qs}{\texttt{ }} \href{https://david-dm.org/ljharb/qs?type=dev}{\texttt{ }} \mbox{[}\mbox{]}\mbox{[}license-\/url\mbox{]} \href{http://npm-stat.com/charts.html?package=qs}{\texttt{ }}

\href{https://npmjs.org/package/qs}{\texttt{ }}

A querystring parsing and stringifying library with some added security.

Lead Maintainer\+: \href{https://github.com/ljharb}{\texttt{ Jordan Harband}}

The {\bfseries{qs}} module was originally created and maintained by \href{https://github.com/visionmedia/node-querystring}{\texttt{ TJ Holowaychuk}}.\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23716}{}\doxysection{Usage}\label{md_sfcode_node_modules_qs_README_autotoc_md23716}

\begin{DoxyCode}{0}
\DoxyCodeLine{var qs = require('qs');}
\DoxyCodeLine{var assert = require('assert');}
\DoxyCodeLine{}
\DoxyCodeLine{var obj = qs.parse('a=c');}
\DoxyCodeLine{assert.deepEqual(obj, \{ a: 'c' \});}
\DoxyCodeLine{}
\DoxyCodeLine{var str = qs.stringify(obj);}
\DoxyCodeLine{assert.equal(str, 'a=c'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23717}{}\doxysubsection{Parsing Objects}\label{md_sfcode_node_modules_qs_README_autotoc_md23717}
\mbox{[}\mbox{]}(\#prevent\+Eval) 
\begin{DoxyCode}{0}
\DoxyCodeLine{qs.parse(string, [options]); }

\end{DoxyCode}


{\bfseries{qs}} allows you to create nested objects within your query strings, by surrounding the name of sub-\/keys with square brackets {\ttfamily \mbox{[}\mbox{]}}. For example, the string `\textquotesingle{}foo\mbox{[}bar\mbox{]}=baz'\`{} converts to\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.deepEqual(qs.parse('foo[bar]=baz'), \{}
\DoxyCodeLine{    foo: \{}
\DoxyCodeLine{        bar: 'baz'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


When using the {\ttfamily plain\+Objects} option the parsed value is returned as a null object, created via {\ttfamily Object.\+create(null)} and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var nullObject = qs.parse('a[hasOwnProperty]=b', \{ plainObjects: true \});}
\DoxyCodeLine{assert.deepEqual(nullObject, \{ a: \{ hasOwnProperty: 'b' \} \}); }

\end{DoxyCode}


By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use {\ttfamily plain\+Objects} as mentioned above, or set {\ttfamily allow\+Prototypes} to {\ttfamily true} which will allow user input to overwrite those properties. {\itshape WARNING} It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.


\begin{DoxyCode}{0}
\DoxyCodeLine{var protoObject = qs.parse('a[hasOwnProperty]=b', \{ allowPrototypes: true \});}
\DoxyCodeLine{assert.deepEqual(protoObject, \{ a: \{ hasOwnProperty: 'b' \} \}); }

\end{DoxyCode}


URI encoded strings work too\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.deepEqual(qs.parse('a\%5Bb\%5D=c'), \{}
\DoxyCodeLine{    a: \{ b: 'c' \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


You can also nest your objects, like `\textquotesingle{}foo\mbox{[}bar\mbox{]}\mbox{[}baz\mbox{]}=foobarbaz'\`{}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), \{}
\DoxyCodeLine{    foo: \{}
\DoxyCodeLine{        bar: \{}
\DoxyCodeLine{            baz: 'foobarbaz'}
\DoxyCodeLine{        \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


By default, when nesting objects {\bfseries{qs}} will only parse up to 5 children deep. This means if you attempt to parse a string like `\textquotesingle{}a\mbox{[}b\mbox{]}\mbox{[}c\mbox{]}\mbox{[}d\mbox{]}\mbox{[}e\mbox{]}\mbox{[}f\mbox{]}\mbox{[}g\mbox{]}\mbox{[}h\mbox{]}\mbox{[}i\mbox{]}=j'\`{} your resulting object will be\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var expected = \{}
\DoxyCodeLine{    a: \{}
\DoxyCodeLine{        b: \{}
\DoxyCodeLine{            c: \{}
\DoxyCodeLine{                d: \{}
\DoxyCodeLine{                    e: \{}
\DoxyCodeLine{                        f: \{}
\DoxyCodeLine{                            '[g][h][i]': 'j'}
\DoxyCodeLine{                        \}}
\DoxyCodeLine{                    \}}
\DoxyCodeLine{                \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{        \}}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{var string = 'a[b][c][d][e][f][g][h][i]=j';}
\DoxyCodeLine{assert.deepEqual(qs.parse(string), expected); }

\end{DoxyCode}


This depth can be overridden by passing a {\ttfamily depth} option to {\ttfamily qs.\+parse(string, \mbox{[}options\mbox{]})}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var deep = qs.parse('a[b][c][d][e][f][g][h][i]=j', \{ depth: 1 \});}
\DoxyCodeLine{assert.deepEqual(deep, \{ a: \{ b: \{ '[c][d][e][f][g][h][i]': 'j' \} \} \}); }

\end{DoxyCode}


The depth limit helps mitigate abuse when {\bfseries{qs}} is used to parse user input, and it is recommended to keep it a reasonably small number.

For similar reasons, by default {\bfseries{qs}} will only parse up to 1000 parameters. This can be overridden by passing a {\ttfamily parameter\+Limit} option\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var limited = qs.parse('a=b\&c=d', \{ parameterLimit: 1 \});}
\DoxyCodeLine{assert.deepEqual(limited, \{ a: 'b' \}); }

\end{DoxyCode}


To bypass the leading question mark, use {\ttfamily ignore\+Query\+Prefix}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var prefixed = qs.parse('?a=b\&c=d', \{ ignoreQueryPrefix: true \});}
\DoxyCodeLine{assert.deepEqual(prefixed, \{ a: 'b', c: 'd' \}); }

\end{DoxyCode}


An optional delimiter can also be passed\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var delimited = qs.parse('a=b;c=d', \{ delimiter: ';' \});}
\DoxyCodeLine{assert.deepEqual(delimited, \{ a: 'b', c: 'd' \}); }

\end{DoxyCode}


Delimiters can be a regular expression too\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var regexed = qs.parse('a=b;c=d,e=f', \{ delimiter: /[;,]/ \});}
\DoxyCodeLine{assert.deepEqual(regexed, \{ a: 'b', c: 'd', e: 'f' \}); }

\end{DoxyCode}


Option {\ttfamily allow\+Dots} can be used to enable dot notation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withDots = qs.parse('a.b=c', \{ allowDots: true \});}
\DoxyCodeLine{assert.deepEqual(withDots, \{ a: \{ b: 'c' \} \}); }

\end{DoxyCode}


If you have to deal with legacy browsers or services, there\textquotesingle{}s also support for decoding percent-\/encoded octets as iso-\/8859-\/1\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var oldCharset = qs.parse('a=\%A7', \{ charset: 'iso-\/8859-\/1' \});}
\DoxyCodeLine{assert.deepEqual(oldCharset, \{ a: '§' \}); }

\end{DoxyCode}


Some services add an initial {\ttfamily utf8=✓} value to forms so that old Internet Explorer versions are more likely to submit the form as utf-\/8. Additionally, the server can check the value against wrong encodings of the checkmark character and detect that a query string or {\ttfamily application/x-\/www-\/form-\/urlencoded} body was {\itshape not} sent as utf-\/8, eg. if the form had an {\ttfamily accept-\/charset} parameter or the containing page had a different character set.

{\bfseries{qs}} supports this mechanism via the {\ttfamily charset\+Sentinel} option. If specified, the {\ttfamily utf8} parameter will be omitted from the returned object. It will be used to switch to {\ttfamily iso-\/8859-\/1}/{\ttfamily utf-\/8} mode depending on how the checkmark is encoded.

{\bfseries{Important}}\+: When you specify both the {\ttfamily charset} option and the {\ttfamily charset\+Sentinel} option, the {\ttfamily charset} will be overridden when the request contains a {\ttfamily utf8} parameter from which the actual charset can be deduced. In that sense the {\ttfamily charset} will behave as the default charset rather than the authoritative charset.


\begin{DoxyCode}{0}
\DoxyCodeLine{var detectedAsUtf8 = qs.parse('utf8=\%E2\%9C\%93\&a=\%C3\%B8', \{}
\DoxyCodeLine{    charset: 'iso-\/8859-\/1',}
\DoxyCodeLine{    charsetSentinel: true}
\DoxyCodeLine{\});}
\DoxyCodeLine{assert.deepEqual(detectedAsUtf8, \{ a: 'ø' \});}
\DoxyCodeLine{}
\DoxyCodeLine{// Browsers encode the checkmark as \&\#10003; when submitting as iso-\/8859-\/1:}
\DoxyCodeLine{var detectedAsIso8859\_1 = qs.parse('utf8=\%26\%2310003\%3B\&a=\%F8', \{}
\DoxyCodeLine{    charset: 'utf-\/8',}
\DoxyCodeLine{    charsetSentinel: true}
\DoxyCodeLine{\});}
\DoxyCodeLine{assert.deepEqual(detectedAsIso8859\_1, \{ a: 'ø' \}); }

\end{DoxyCode}


If you want to decode the {\ttfamily \&\#...;} syntax to the actual character, you can specify the {\ttfamily interpret\+Numeric\+Entities} option as well\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var detectedAsIso8859\_1 = qs.parse('a=\%26\%239786\%3B', \{}
\DoxyCodeLine{    charset: 'iso-\/8859-\/1',}
\DoxyCodeLine{    interpretNumericEntities: true}
\DoxyCodeLine{\});}
\DoxyCodeLine{assert.deepEqual(detectedAsIso8859\_1, \{ a: '☺' \}); }

\end{DoxyCode}


It also works when the charset has been detected in {\ttfamily charset\+Sentinel} mode.\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23718}{}\doxysubsection{Parsing Arrays}\label{md_sfcode_node_modules_qs_README_autotoc_md23718}
{\bfseries{qs}} can also parse arrays using a similar {\ttfamily \mbox{[}\mbox{]}} notation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withArray = qs.parse('a[]=b\&a[]=c');}
\DoxyCodeLine{assert.deepEqual(withArray, \{ a: ['b', 'c'] \}); }

\end{DoxyCode}


You may specify an index as well\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withIndexes = qs.parse('a[1]=c\&a[0]=b');}
\DoxyCodeLine{assert.deepEqual(withIndexes, \{ a: ['b', 'c'] \}); }

\end{DoxyCode}


Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number to create an array. When creating arrays with specific indices, {\bfseries{qs}} will compact a sparse array to only the existing values preserving their order\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var noSparse = qs.parse('a[1]=b\&a[15]=c');}
\DoxyCodeLine{assert.deepEqual(noSparse, \{ a: ['b', 'c'] \}); }

\end{DoxyCode}


Note that an empty string is also a value, and will be preserved\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withEmptyString = qs.parse('a[]=\&a[]=b');}
\DoxyCodeLine{assert.deepEqual(withEmptyString, \{ a: ['', 'b'] \});}
\DoxyCodeLine{}
\DoxyCodeLine{var withIndexedEmptyString = qs.parse('a[0]=b\&a[1]=\&a[2]=c');}
\DoxyCodeLine{assert.deepEqual(withIndexedEmptyString, \{ a: ['b', '', 'c'] \}); }

\end{DoxyCode}


{\bfseries{qs}} will also limit specifying indices in an array to a maximum index of {\ttfamily 20}. Any array members with an index of greater than {\ttfamily 20} will instead be converted to an object with the index as the key. This is needed to handle cases when someone sent, for example, {\ttfamily a\mbox{[}999999999\mbox{]}} and it will take significant time to iterate over this huge array.


\begin{DoxyCode}{0}
\DoxyCodeLine{var withMaxIndex = qs.parse('a[100]=b');}
\DoxyCodeLine{assert.deepEqual(withMaxIndex, \{ a: \{ '100': 'b' \} \}); }

\end{DoxyCode}


This limit can be overridden by passing an {\ttfamily array\+Limit} option\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withArrayLimit = qs.parse('a[1]=b', \{ arrayLimit: 0 \});}
\DoxyCodeLine{assert.deepEqual(withArrayLimit, \{ a: \{ '1': 'b' \} \}); }

\end{DoxyCode}


To disable array parsing entirely, set {\ttfamily parse\+Arrays} to {\ttfamily false}.


\begin{DoxyCode}{0}
\DoxyCodeLine{var noParsingArrays = qs.parse('a[]=b', \{ parseArrays: false \});}
\DoxyCodeLine{assert.deepEqual(noParsingArrays, \{ a: \{ '0': 'b' \} \}); }

\end{DoxyCode}


If you mix notations, {\bfseries{qs}} will merge the two items into an object\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var mixedNotation = qs.parse('a[0]=b\&a[b]=c');}
\DoxyCodeLine{assert.deepEqual(mixedNotation, \{ a: \{ '0': 'b', b: 'c' \} \}); }

\end{DoxyCode}


You can also create arrays of objects\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var arraysOfObjects = qs.parse('a[][b]=c');}
\DoxyCodeLine{assert.deepEqual(arraysOfObjects, \{ a: [\{ b: 'c' \}] \}); }

\end{DoxyCode}


Some people use comma to join array, {\bfseries{qs}} can parse it\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var arraysOfObjects = qs.parse('a=b,c', \{ comma: true \})}
\DoxyCodeLine{assert.deepEqual(arraysOfObjects, \{ a: ['b', 'c'] \}) }

\end{DoxyCode}
 ({\itshape this cannot convert nested objects, such as {\ttfamily a=\{b\+:1\},\{c\+:d\}}})\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23719}{}\doxysubsection{Stringifying}\label{md_sfcode_node_modules_qs_README_autotoc_md23719}
\mbox{[}\mbox{]}(\#prevent\+Eval) 
\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(object, [options]); }

\end{DoxyCode}


When stringifying, {\bfseries{qs}} by default URI encodes output. Objects are stringified as you would expect\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b' \}), 'a=b');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: \{ b: 'c' \} \}), 'a\%5Bb\%5D=c'); }

\end{DoxyCode}


This encoding can be disabled by setting the {\ttfamily encode} option to {\ttfamily false}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var unencoded = qs.stringify(\{ a: \{ b: 'c' \} \}, \{ encode: false \});}
\DoxyCodeLine{assert.equal(unencoded, 'a[b]=c'); }

\end{DoxyCode}


Encoding can be disabled for keys by setting the {\ttfamily encode\+Values\+Only} option to {\ttfamily true}\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{var encodedValues = qs.stringify(}
\DoxyCodeLine{    \{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] \},}
\DoxyCodeLine{    \{ encodeValuesOnly: true \}}
\DoxyCodeLine{);}
\DoxyCodeLine{assert.equal(encodedValues,'a=b\&c[0]=d\&c[1]=e\%3Df\&f[0][0]=g\&f[1][0]=h'); }

\end{DoxyCode}


This encoding can also be replaced by a custom encoding method set as {\ttfamily encoder} option\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var encoded = qs.stringify(\{ a: \{ b: 'c' \} \}, \{ encoder: function (str) \{}
\DoxyCodeLine{    // Passed in values `a`, `b`, `c`}
\DoxyCodeLine{    return // Return encoded string}
\DoxyCodeLine{\}\}) }

\end{DoxyCode}


\+\_\+(Note\+: the {\ttfamily encoder} option does not apply if {\ttfamily encode} is {\ttfamily false})\+\_\+

Analogue to the {\ttfamily encoder} there is a {\ttfamily decoder} option for {\ttfamily parse} to override decoding of properties and values\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var decoded = qs.parse('x=z', \{ decoder: function (str) \{}
\DoxyCodeLine{    // Passed in values `x`, `z`}
\DoxyCodeLine{    return // Return decoded string}
\DoxyCodeLine{\}\}) }

\end{DoxyCode}


Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases {\itshape will} be URI encoded during real usage.

When arrays are stringified, by default they are given explicit indices\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c', 'd'] \});}
\DoxyCodeLine{// 'a[0]=b\&a[1]=c\&a[2]=d' }

\end{DoxyCode}


You may override this by setting the {\ttfamily indices} option to {\ttfamily false}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c', 'd'] \}, \{ indices: false \});}
\DoxyCodeLine{// 'a=b\&a=c\&a=d' }

\end{DoxyCode}


You may use the {\ttfamily array\+Format} option to specify the format of the output array\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c'] \}, \{ arrayFormat: 'indices' \})}
\DoxyCodeLine{// 'a[0]=b\&a[1]=c'}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c'] \}, \{ arrayFormat: 'brackets' \})}
\DoxyCodeLine{// 'a[]=b\&a[]=c'}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c'] \}, \{ arrayFormat: 'repeat' \})}
\DoxyCodeLine{// 'a=b\&a=c'}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c'] \}, \{ arrayFormat: 'comma' \})}
\DoxyCodeLine{// 'a=b,c' }

\end{DoxyCode}


When objects are stringified, by default they use bracket notation\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(\{ a: \{ b: \{ c: 'd', e: 'f' \} \} \});}
\DoxyCodeLine{// 'a[b][c]=d\&a[b][e]=f' }

\end{DoxyCode}


You may override this to use dot notation by setting the {\ttfamily allow\+Dots} option to {\ttfamily true}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{qs.stringify(\{ a: \{ b: \{ c: 'd', e: 'f' \} \} \}, \{ allowDots: true \});}
\DoxyCodeLine{// 'a.b.c=d\&a.b.e=f' }

\end{DoxyCode}


Empty strings and null values will omit the value, but the equals sign (=) remains in place\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: '' \}), 'a='); }

\end{DoxyCode}


Key with no values (such as an empty object or array) will return nothing\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: [] \}), '');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: \{\} \}), '');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: [\{\}] \}), '');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: \{ b: []\} \}), '');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: \{ b: \{\}\} \}), ''); }

\end{DoxyCode}


Properties that are set to {\ttfamily undefined} will be omitted entirely\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: null, b: undefined \}), 'a='); }

\end{DoxyCode}


The query string may optionally be prepended with a question mark\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b', c: 'd' \}, \{ addQueryPrefix: true \}), '?a=b\&c=d'); }

\end{DoxyCode}


The delimiter may be overridden with stringify as well\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b', c: 'd' \}, \{ delimiter: ';' \}), 'a=b;c=d'); }

\end{DoxyCode}


If you only want to override the serialization of {\ttfamily Date} objects, you can provide a {\ttfamily serialize\+Date} option\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var date = new Date(7);}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: date \}), 'a=1970-\/01-\/01T00:00:00.007Z'.replace(/:/g, '\%3A'));}
\DoxyCodeLine{assert.equal(}
\DoxyCodeLine{    qs.stringify(\{ a: date \}, \{ serializeDate: function (d) \{ return d.getTime(); \} \}),}
\DoxyCodeLine{    'a=7'}
\DoxyCodeLine{); }

\end{DoxyCode}


You may use the {\ttfamily sort} option to affect the order of parameter keys\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{function alphabeticalSort(a, b) \{}
\DoxyCodeLine{    return a.localeCompare(b);}
\DoxyCodeLine{\}}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'c', z: 'y', b : 'f' \}, \{ sort: alphabeticalSort \}), 'a=c\&b=f\&z=y'); }

\end{DoxyCode}


Finally, you can use the {\ttfamily filter} option to restrict which keys will be included in the stringified output. If you pass a function, it will be called for each key to obtain the replacement value. Otherwise, if you pass an array, it will be used to select properties and array indices for stringification\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{function filterFunc(prefix, value) \{}
\DoxyCodeLine{    if (prefix == 'b') \{}
\DoxyCodeLine{        // Return an `undefined` value to omit a property.}
\DoxyCodeLine{        return;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{    if (prefix == 'e[f]') \{}
\DoxyCodeLine{        return value.getTime();}
\DoxyCodeLine{    \}}
\DoxyCodeLine{    if (prefix == 'e[g][0]') \{}
\DoxyCodeLine{        return value * 2;}
\DoxyCodeLine{    \}}
\DoxyCodeLine{    return value;}
\DoxyCodeLine{\}}
\DoxyCodeLine{qs.stringify(\{ a: 'b', c: 'd', e: \{ f: new Date(123), g: [2] \} \}, \{ filter: filterFunc \});}
\DoxyCodeLine{// 'a=b\&c=d\&e[f]=123\&e[g][0]=4'}
\DoxyCodeLine{qs.stringify(\{ a: 'b', c: 'd', e: 'f' \}, \{ filter: ['a', 'e'] \});}
\DoxyCodeLine{// 'a=b\&e=f'}
\DoxyCodeLine{qs.stringify(\{ a: ['b', 'c', 'd'], e: 'f' \}, \{ filter: ['a', 0, 2] \});}
\DoxyCodeLine{// 'a[0]=b\&a[2]=d' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23720}{}\doxysubsection{Handling of $<$tt$>$null$<$/tt$>$ values}\label{md_sfcode_node_modules_qs_README_autotoc_md23720}
By default, {\ttfamily null} values are treated like empty strings\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var withNull = qs.stringify(\{ a: null, b: '' \});}
\DoxyCodeLine{assert.equal(withNull, 'a=\&b='); }

\end{DoxyCode}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{var equalsInsensitive = qs.parse('a\&b=');}
\DoxyCodeLine{assert.deepEqual(equalsInsensitive, \{ a: '', b: '' \}); }

\end{DoxyCode}


To distinguish between {\ttfamily null} values and empty strings use the {\ttfamily strict\+Null\+Handling} flag. In the result string the {\ttfamily null} values have no {\ttfamily =} sign\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var strictNull = qs.stringify(\{ a: null, b: '' \}, \{ strictNullHandling: true \});}
\DoxyCodeLine{assert.equal(strictNull, 'a\&b='); }

\end{DoxyCode}


To parse values without {\ttfamily =} back to {\ttfamily null} use the {\ttfamily strict\+Null\+Handling} flag\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var parsedStrictNull = qs.parse('a\&b=', \{ strictNullHandling: true \});}
\DoxyCodeLine{assert.deepEqual(parsedStrictNull, \{ a: null, b: '' \}); }

\end{DoxyCode}


To completely skip rendering keys with {\ttfamily null} values, use the {\ttfamily skip\+Nulls} flag\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var nullsSkipped = qs.stringify(\{ a: 'b', c: null\}, \{ skipNulls: true \});}
\DoxyCodeLine{assert.equal(nullsSkipped, 'a=b'); }

\end{DoxyCode}


If you\textquotesingle{}re communicating with legacy systems, you can switch to {\ttfamily iso-\/8859-\/1} using the {\ttfamily charset} option\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var iso = qs.stringify(\{ æ: 'æ' \}, \{ charset: 'iso-\/8859-\/1' \});}
\DoxyCodeLine{assert.equal(iso, '\%E6=\%E6'); }

\end{DoxyCode}


Characters that don\textquotesingle{}t exist in {\ttfamily iso-\/8859-\/1} will be converted to numeric entities, similar to what browsers do\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var numeric = qs.stringify(\{ a: '☺' \}, \{ charset: 'iso-\/8859-\/1' \});}
\DoxyCodeLine{assert.equal(numeric, 'a=\%26\%239786\%3B'); }

\end{DoxyCode}


You can use the {\ttfamily charset\+Sentinel} option to announce the character by including an {\ttfamily utf8=✓} parameter with the proper encoding if the checkmark, similar to what Ruby on Rails and others do when submitting forms.


\begin{DoxyCode}{0}
\DoxyCodeLine{var sentinel = qs.stringify(\{ a: '☺' \}, \{ charsetSentinel: true \});}
\DoxyCodeLine{assert.equal(sentinel, 'utf8=\%E2\%9C\%93\&a=\%E2\%98\%BA');}
\DoxyCodeLine{}
\DoxyCodeLine{var isoSentinel = qs.stringify(\{ a: 'æ' \}, \{ charsetSentinel: true, charset: 'iso-\/8859-\/1' \});}
\DoxyCodeLine{assert.equal(isoSentinel, 'utf8=\%26\%2310003\%3B\&a=\%E6'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23721}{}\doxysubsection{Dealing with special character sets}\label{md_sfcode_node_modules_qs_README_autotoc_md23721}
By default the encoding and decoding of characters is done in {\ttfamily utf-\/8}, and {\ttfamily iso-\/8859-\/1} support is also built in via the {\ttfamily charset} parameter.

If you wish to encode querystrings to a different character set (i.\+e. \href{https://en.wikipedia.org/wiki/Shift_JIS}{\texttt{ Shift JIS}}) you can use the \href{https://github.com/martinheidegger/qs-iconv}{\texttt{ {\ttfamily qs-\/iconv}}} library\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var encoder = require('qs-\/iconv/encoder')('shift\_jis');}
\DoxyCodeLine{var shiftJISEncoded = qs.stringify(\{ a: 'こんにちは！' \}, \{ encoder: encoder \});}
\DoxyCodeLine{assert.equal(shiftJISEncoded, 'a=\%82\%B1\%82\%F1\%82\%C9\%82\%BF\%82\%CD\%81I'); }

\end{DoxyCode}


This also works for decoding of query strings\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var decoder = require('qs-\/iconv/decoder')('shift\_jis');}
\DoxyCodeLine{var obj = qs.parse('a=\%82\%B1\%82\%F1\%82\%C9\%82\%BF\%82\%CD\%81I', \{ decoder: decoder \});}
\DoxyCodeLine{assert.deepEqual(obj, \{ a: 'こんにちは！' \}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_qs_README_autotoc_md23722}{}\doxysubsection{RFC 3986 and RFC 1738 space encoding}\label{md_sfcode_node_modules_qs_README_autotoc_md23722}
RFC3986 used as default option and encodes \textquotesingle{} \textquotesingle{} to {\itshape \%20} which is backward compatible. In the same time, output can be stringified as per RFC1738 with \textquotesingle{} \textquotesingle{} equal to \textquotesingle{}+\textquotesingle{}.


\begin{DoxyCode}{0}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b c' \}), 'a=b\%20c');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b c' \}, \{ format : 'RFC3986' \}), 'a=b\%20c');}
\DoxyCodeLine{assert.equal(qs.stringify(\{ a: 'b c' \}, \{ format : 'RFC1738' \}), 'a=b+c'); }

\end{DoxyCode}
 