{"source":"doc/api/querystring.md","modules":[{"textRaw":"Query String","name":"querystring","stability": 2,"stabilityText":"Stable","desc":"<p>The <code>querystring</code> module provides utilities for parsing and formatting URL\nquery strings. It can be accessed using:</p>\n<pre><code class=\"lang-js\">const querystring = require(&#39;querystring&#39;);\n</code></pre>\n","methods":[{"textRaw":"querystring.escape(str)","type":"method","name":"escape","meta":{"added":["v0.1.25"]},"signatures":[{"params":[{"textRaw":"`str`{String}","name":"str","type":"String"}]},{"params":[{"name":"str"}]}],"desc":"<p>The <code>querystring.escape()</code> method performs URL percent-encoding on the given\n<code>str</code> in a manner that is optimized for the specific requirements of URL\nquery strings.</p>\n<p>The <code>querystring.escape()</code> method is used by <code>querystring.stringify()</code> and is\ngenerally not expected to be used directly. It is exported primarily to allow\napplication code to provide a replacement percent-encoding implementation if\nnecessary by assigning <code>querystring.escape</code> to an alternative function.</p>\n"},{"textRaw":"querystring.parse(str[, sep[, eq[, options]]])","type":"method","name":"parse","meta":{"added":["v0.1.25"]},"signatures":[{"params":[{"textRaw":"`str`{String}The URL query string to parse ","name":"str","type":"String","desc":"The URL query string to parse"},{"textRaw":"`sep`{String}The substring used to delimit key and value pairs in the query string. Defaults to `'&'`. ","name":"sep","type":"String","desc":"The substring used to delimit key and value pairs in the query string. Defaults to `'&'`.","optional": true},{"textRaw":"`eq`{String}. The substring used to delimit keys and values in the query string. Defaults to `'='`. ","name":"eq","type":"String","desc":". The substring used to delimit keys and values in the query string. Defaults to `'='`.","optional": true},{"textRaw":"`options`{Object}","options":[{"textRaw":"`decodeURIComponent`{Function}The function to use when decoding percent-encoded characters in the query string. Defaults to `querystring.unescape()`. ","name":"decodeURIComponent","type":"Function","desc":"The function to use when decoding percent-encoded characters in the query string. Defaults to `querystring.unescape()`."},{"textRaw":"`maxKeys`{number}Specifies the maximum number of keys to parse. Defaults to `1000`. Specify `0` to remove key counting limitations. ","name":"maxKeys","type":"number","desc":"Specifies the maximum number of keys to parse. Defaults to `1000`. Specify `0` to remove key counting limitations."}],"name":"options","type":"Object","optional": true}]},{"params":[{"name":"str"},{"name":"sep","optional": true},{"name":"eq","optional": true},{"name":"options","optional": true}]}],"desc":"<p>The <code>querystring.parse()</code> method parses a URL query string (<code>str</code>) into a\ncollection of key and value pairs.</p>\n<p>For example, the query string <code>&#39;foo=bar&amp;abc=xyz&amp;abc=123&#39;</code> is parsed into:</p>\n<pre><code class=\"lang-js\">{\n  foo: &#39;bar&#39;,\n  abc:[&#39;xyz&#39;, &#39;123&#39;]\n}\n</code></pre>\n<p><em>Note</em>: The object returned by the <code>querystring.parse()</code> method <em>does not</em>\nprototypically extend from the JavaScript <code>Object</code>. This means that the\ntypical <code>Object</code> methods such as <code>obj.toString()</code>, <code>obj.hashOwnProperty()</code>,\nand others are not defined and <em>will not work</em>.</p>\n<p>By default, percent-encoded characters within the query string will be assumed\nto use UTF-8 encoding. If an alternative character encoding is used, then an\nalternative <code>decodeURIComponent</code> option will need to be specified as illustrated\nin the following example:</p>\n<pre><code class=\"lang-js\">// Assuming gbkDecodeURIComponent function already exists...\n\nquerystring.parse(&#39;w=%D6%D0%CE%C4&amp;foo=bar&#39;, null, null,\n{decodeURIComponent: gbkDecodeURIComponent})\n</code></pre>\n"},{"textRaw":"querystring.stringify(obj[, sep[, eq[, options]]])","type":"method","name":"stringify","meta":{"added":["v0.1.25"]},"signatures":[{"params":[{"textRaw":"`obj`{Object}The object to serialize into a URL query string ","name":"obj","type":"Object","desc":"The object to serialize into a URL query string"},{"textRaw":"`sep`{String}The substring used to delimit key and value pairs in the query string. Defaults to `'&'`. ","name":"sep","type":"String","desc":"The substring used to delimit key and value pairs in the query string. Defaults to `'&'`.","optional": true},{"textRaw":"`eq`{String}. The substring used to delimit keys and values in the query string. Defaults to `'='`. ","name":"eq","type":"String","desc":". The substring used to delimit keys and values in the query string. Defaults to `'='`.","optional": true},{"textRaw":"`options` ","options":[{"textRaw":"`encodeURIComponent`{Function}The function to use when converting URL-unsafe characters to percent-encoding in the query string. Defaults to `querystring.escape()`. ","name":"encodeURIComponent","type":"Function","desc":"The function to use when converting URL-unsafe characters to percent-encoding in the query string. Defaults to `querystring.escape()`."}],"name":"options","optional": true}]},{"params":[{"name":"obj"},{"name":"sep","optional": true},{"name":"eq","optional": true},{"name":"options","optional": true}]}],"desc":"<p>The <code>querystring.stringify()</code> method produces a URL query string from a\ngiven <code>obj</code> by iterating through the object&#39;s &quot;own properties&quot;.</p>\n<p>For example:</p>\n<pre><code class=\"lang-js\">querystring.stringify({foo: &#39;bar&#39;, baz:[&#39;qux&#39;, &#39;quux&#39;], corge: &#39;&#39;})\n// returns &#39;foo=bar&amp;baz=qux&amp;baz=quux&amp;corge=&#39;\n\nquerystring.stringify({foo: &#39;bar&#39;, baz: &#39;qux&#39;}, &#39;;&#39;, &#39;:&#39;)\n// returns &#39;foo:bar;baz:qux&#39;\n</code></pre>\n<p>By default, characters requiring percent-encoding within the query string will\nbe encoded as UTF-8. If an alternative encoding is required, then an alternative\n<code>encodeURIComponent</code> option will need to be specified as illustrated in the\nfollowing example:</p>\n<pre><code class=\"lang-js\">// Assuming gbkEncodeURIComponent function already exists,\n\nquerystring.stringify({w: &#39;中文&#39;, foo: &#39;bar&#39;}, null, null,\n{encodeURIComponent: gbkEncodeURIComponent})\n</code></pre>\n"},{"textRaw":"querystring.unescape(str)","type":"method","name":"unescape","meta":{"added":["v0.1.25"]},"signatures":[{"params":[{"textRaw":"`str`{String}","name":"str","type":"String"}]},{"params":[{"name":"str"}]}],"desc":"<p>The <code>querystring.unescape()</code> method performs decoding of URL percent-encoded\ncharacters on the given <code>str</code>.</p>\n<p>The <code>querystring.unescape()</code> method is used by <code>querystring.parse()</code> and is\ngenerally not expected to be used directly. It is exported primarily to allow\napplication code to provide a replacement decoding implementation if\nnecessary by assigning <code>querystring.unescape</code> to an alternative function.</p>\n<p>By default, the <code>querystring.unescape()</code> method will attempt to use the\nJavaScript built-in <code>decodeURIComponent()</code> method to decode. If that fails,\na safer equivalent that does not throw on malformed URLs will be used.</p>\n"}],"type":"module","displayName":"querystring"}]}