xref: /third_party/node/doc/api/querystring.json (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci{
21cb0ef41Sopenharmony_ci  "type": "module",
31cb0ef41Sopenharmony_ci  "source": "doc/api/querystring.md",
41cb0ef41Sopenharmony_ci  "modules": [
51cb0ef41Sopenharmony_ci    {
61cb0ef41Sopenharmony_ci      "textRaw": "Query string",
71cb0ef41Sopenharmony_ci      "name": "querystring",
81cb0ef41Sopenharmony_ci      "introduced_in": "v0.1.25",
91cb0ef41Sopenharmony_ci      "stability": 2,
101cb0ef41Sopenharmony_ci      "stabilityText": "Stable",
111cb0ef41Sopenharmony_ci      "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v18.20.1/lib/querystring.js\">lib/querystring.js</a></p>\n<p>The <code>node:querystring</code> module provides utilities for parsing and formatting URL\nquery strings. It can be accessed using:</p>\n<pre><code class=\"language-js\">const querystring = require('node:querystring');\n</code></pre>\n<p><code>querystring</code> is more performant than <a href=\"url.html#class-urlsearchparams\" class=\"type\">&lt;URLSearchParams&gt;</a> but is not a\nstandardized API. Use <a href=\"url.html#class-urlsearchparams\" class=\"type\">&lt;URLSearchParams&gt;</a> when performance is not critical or\nwhen compatibility with browser code is desirable.</p>",
121cb0ef41Sopenharmony_ci      "methods": [
131cb0ef41Sopenharmony_ci        {
141cb0ef41Sopenharmony_ci          "textRaw": "`querystring.decode()`",
151cb0ef41Sopenharmony_ci          "type": "method",
161cb0ef41Sopenharmony_ci          "name": "decode",
171cb0ef41Sopenharmony_ci          "meta": {
181cb0ef41Sopenharmony_ci            "added": [
191cb0ef41Sopenharmony_ci              "v0.1.99"
201cb0ef41Sopenharmony_ci            ],
211cb0ef41Sopenharmony_ci            "changes": []
221cb0ef41Sopenharmony_ci          },
231cb0ef41Sopenharmony_ci          "signatures": [
241cb0ef41Sopenharmony_ci            {
251cb0ef41Sopenharmony_ci              "params": []
261cb0ef41Sopenharmony_ci            }
271cb0ef41Sopenharmony_ci          ],
281cb0ef41Sopenharmony_ci          "desc": "<p>The <code>querystring.decode()</code> function is an alias for <code>querystring.parse()</code>.</p>"
291cb0ef41Sopenharmony_ci        },
301cb0ef41Sopenharmony_ci        {
311cb0ef41Sopenharmony_ci          "textRaw": "`querystring.encode()`",
321cb0ef41Sopenharmony_ci          "type": "method",
331cb0ef41Sopenharmony_ci          "name": "encode",
341cb0ef41Sopenharmony_ci          "meta": {
351cb0ef41Sopenharmony_ci            "added": [
361cb0ef41Sopenharmony_ci              "v0.1.99"
371cb0ef41Sopenharmony_ci            ],
381cb0ef41Sopenharmony_ci            "changes": []
391cb0ef41Sopenharmony_ci          },
401cb0ef41Sopenharmony_ci          "signatures": [
411cb0ef41Sopenharmony_ci            {
421cb0ef41Sopenharmony_ci              "params": []
431cb0ef41Sopenharmony_ci            }
441cb0ef41Sopenharmony_ci          ],
451cb0ef41Sopenharmony_ci          "desc": "<p>The <code>querystring.encode()</code> function is an alias for <code>querystring.stringify()</code>.</p>"
461cb0ef41Sopenharmony_ci        },
471cb0ef41Sopenharmony_ci        {
481cb0ef41Sopenharmony_ci          "textRaw": "`querystring.escape(str)`",
491cb0ef41Sopenharmony_ci          "type": "method",
501cb0ef41Sopenharmony_ci          "name": "escape",
511cb0ef41Sopenharmony_ci          "meta": {
521cb0ef41Sopenharmony_ci            "added": [
531cb0ef41Sopenharmony_ci              "v0.1.25"
541cb0ef41Sopenharmony_ci            ],
551cb0ef41Sopenharmony_ci            "changes": []
561cb0ef41Sopenharmony_ci          },
571cb0ef41Sopenharmony_ci          "signatures": [
581cb0ef41Sopenharmony_ci            {
591cb0ef41Sopenharmony_ci              "params": [
601cb0ef41Sopenharmony_ci                {
611cb0ef41Sopenharmony_ci                  "textRaw": "`str` {string}",
621cb0ef41Sopenharmony_ci                  "name": "str",
631cb0ef41Sopenharmony_ci                  "type": "string"
641cb0ef41Sopenharmony_ci                }
651cb0ef41Sopenharmony_ci              ]
661cb0ef41Sopenharmony_ci            }
671cb0ef41Sopenharmony_ci          ],
681cb0ef41Sopenharmony_ci          "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>"
691cb0ef41Sopenharmony_ci        },
701cb0ef41Sopenharmony_ci        {
711cb0ef41Sopenharmony_ci          "textRaw": "`querystring.parse(str[, sep[, eq[, options]]])`",
721cb0ef41Sopenharmony_ci          "type": "method",
731cb0ef41Sopenharmony_ci          "name": "parse",
741cb0ef41Sopenharmony_ci          "meta": {
751cb0ef41Sopenharmony_ci            "added": [
761cb0ef41Sopenharmony_ci              "v0.1.25"
771cb0ef41Sopenharmony_ci            ],
781cb0ef41Sopenharmony_ci            "changes": [
791cb0ef41Sopenharmony_ci              {
801cb0ef41Sopenharmony_ci                "version": "v8.0.0",
811cb0ef41Sopenharmony_ci                "pr-url": "https://github.com/nodejs/node/pull/10967",
821cb0ef41Sopenharmony_ci                "description": "Multiple empty entries are now parsed correctly (e.g. `&=&=`)."
831cb0ef41Sopenharmony_ci              },
841cb0ef41Sopenharmony_ci              {
851cb0ef41Sopenharmony_ci                "version": "v6.0.0",
861cb0ef41Sopenharmony_ci                "pr-url": "https://github.com/nodejs/node/pull/6055",
871cb0ef41Sopenharmony_ci                "description": "The returned object no longer inherits from `Object.prototype`."
881cb0ef41Sopenharmony_ci              },
891cb0ef41Sopenharmony_ci              {
901cb0ef41Sopenharmony_ci                "version": [
911cb0ef41Sopenharmony_ci                  "v6.0.0",
921cb0ef41Sopenharmony_ci                  "v4.2.4"
931cb0ef41Sopenharmony_ci                ],
941cb0ef41Sopenharmony_ci                "pr-url": "https://github.com/nodejs/node/pull/3807",
951cb0ef41Sopenharmony_ci                "description": "The `eq` parameter may now have a length of more than `1`."
961cb0ef41Sopenharmony_ci              }
971cb0ef41Sopenharmony_ci            ]
981cb0ef41Sopenharmony_ci          },
991cb0ef41Sopenharmony_ci          "signatures": [
1001cb0ef41Sopenharmony_ci            {
1011cb0ef41Sopenharmony_ci              "params": [
1021cb0ef41Sopenharmony_ci                {
1031cb0ef41Sopenharmony_ci                  "textRaw": "`str` {string} The URL query string to parse",
1041cb0ef41Sopenharmony_ci                  "name": "str",
1051cb0ef41Sopenharmony_ci                  "type": "string",
1061cb0ef41Sopenharmony_ci                  "desc": "The URL query string to parse"
1071cb0ef41Sopenharmony_ci                },
1081cb0ef41Sopenharmony_ci                {
1091cb0ef41Sopenharmony_ci                  "textRaw": "`sep` {string} The substring used to delimit key and value pairs in the query string. **Default:** `'&'`.",
1101cb0ef41Sopenharmony_ci                  "name": "sep",
1111cb0ef41Sopenharmony_ci                  "type": "string",
1121cb0ef41Sopenharmony_ci                  "default": "`'&'`",
1131cb0ef41Sopenharmony_ci                  "desc": "The substring used to delimit key and value pairs in the query string."
1141cb0ef41Sopenharmony_ci                },
1151cb0ef41Sopenharmony_ci                {
1161cb0ef41Sopenharmony_ci                  "textRaw": "`eq` {string}. The substring used to delimit keys and values in the query string. **Default:** `'='`.",
1171cb0ef41Sopenharmony_ci                  "name": "eq",
1181cb0ef41Sopenharmony_ci                  "type": "string",
1191cb0ef41Sopenharmony_ci                  "default": "`'='`",
1201cb0ef41Sopenharmony_ci                  "desc": ". The substring used to delimit keys and values in the query string."
1211cb0ef41Sopenharmony_ci                },
1221cb0ef41Sopenharmony_ci                {
1231cb0ef41Sopenharmony_ci                  "textRaw": "`options` {Object}",
1241cb0ef41Sopenharmony_ci                  "name": "options",
1251cb0ef41Sopenharmony_ci                  "type": "Object",
1261cb0ef41Sopenharmony_ci                  "options": [
1271cb0ef41Sopenharmony_ci                    {
1281cb0ef41Sopenharmony_ci                      "textRaw": "`decodeURIComponent` {Function} The function to use when decoding percent-encoded characters in the query string. **Default:** `querystring.unescape()`.",
1291cb0ef41Sopenharmony_ci                      "name": "decodeURIComponent",
1301cb0ef41Sopenharmony_ci                      "type": "Function",
1311cb0ef41Sopenharmony_ci                      "default": "`querystring.unescape()`",
1321cb0ef41Sopenharmony_ci                      "desc": "The function to use when decoding percent-encoded characters in the query string."
1331cb0ef41Sopenharmony_ci                    },
1341cb0ef41Sopenharmony_ci                    {
1351cb0ef41Sopenharmony_ci                      "textRaw": "`maxKeys` {number} Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations. **Default:** `1000`.",
1361cb0ef41Sopenharmony_ci                      "name": "maxKeys",
1371cb0ef41Sopenharmony_ci                      "type": "number",
1381cb0ef41Sopenharmony_ci                      "default": "`1000`",
1391cb0ef41Sopenharmony_ci                      "desc": "Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations."
1401cb0ef41Sopenharmony_ci                    }
1411cb0ef41Sopenharmony_ci                  ]
1421cb0ef41Sopenharmony_ci                }
1431cb0ef41Sopenharmony_ci              ]
1441cb0ef41Sopenharmony_ci            }
1451cb0ef41Sopenharmony_ci          ],
1461cb0ef41Sopenharmony_ci          "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>'foo=bar&#x26;abc=xyz&#x26;abc=123'</code> is parsed into:</p>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">{\n  foo: 'bar',\n  abc: ['xyz', '123']\n}\n</code></pre>\n<p>The object returned by the <code>querystring.parse()</code> method <em>does not</em>\nprototypically inherit from the JavaScript <code>Object</code>. This means that typical\n<code>Object</code> methods such as <code>obj.toString()</code>, <code>obj.hasOwnProperty()</code>, and others\nare 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:</p>\n<pre><code class=\"language-js\">// Assuming gbkDecodeURIComponent function already exists...\n\nquerystring.parse('w=%D6%D0%CE%C4&#x26;foo=bar', null, null,\n                  { decodeURIComponent: gbkDecodeURIComponent });\n</code></pre>"
1471cb0ef41Sopenharmony_ci        },
1481cb0ef41Sopenharmony_ci        {
1491cb0ef41Sopenharmony_ci          "textRaw": "`querystring.stringify(obj[, sep[, eq[, options]]])`",
1501cb0ef41Sopenharmony_ci          "type": "method",
1511cb0ef41Sopenharmony_ci          "name": "stringify",
1521cb0ef41Sopenharmony_ci          "meta": {
1531cb0ef41Sopenharmony_ci            "added": [
1541cb0ef41Sopenharmony_ci              "v0.1.25"
1551cb0ef41Sopenharmony_ci            ],
1561cb0ef41Sopenharmony_ci            "changes": []
1571cb0ef41Sopenharmony_ci          },
1581cb0ef41Sopenharmony_ci          "signatures": [
1591cb0ef41Sopenharmony_ci            {
1601cb0ef41Sopenharmony_ci              "params": [
1611cb0ef41Sopenharmony_ci                {
1621cb0ef41Sopenharmony_ci                  "textRaw": "`obj` {Object} The object to serialize into a URL query string",
1631cb0ef41Sopenharmony_ci                  "name": "obj",
1641cb0ef41Sopenharmony_ci                  "type": "Object",
1651cb0ef41Sopenharmony_ci                  "desc": "The object to serialize into a URL query string"
1661cb0ef41Sopenharmony_ci                },
1671cb0ef41Sopenharmony_ci                {
1681cb0ef41Sopenharmony_ci                  "textRaw": "`sep` {string} The substring used to delimit key and value pairs in the query string. **Default:** `'&'`.",
1691cb0ef41Sopenharmony_ci                  "name": "sep",
1701cb0ef41Sopenharmony_ci                  "type": "string",
1711cb0ef41Sopenharmony_ci                  "default": "`'&'`",
1721cb0ef41Sopenharmony_ci                  "desc": "The substring used to delimit key and value pairs in the query string."
1731cb0ef41Sopenharmony_ci                },
1741cb0ef41Sopenharmony_ci                {
1751cb0ef41Sopenharmony_ci                  "textRaw": "`eq` {string}. The substring used to delimit keys and values in the query string. **Default:** `'='`.",
1761cb0ef41Sopenharmony_ci                  "name": "eq",
1771cb0ef41Sopenharmony_ci                  "type": "string",
1781cb0ef41Sopenharmony_ci                  "default": "`'='`",
1791cb0ef41Sopenharmony_ci                  "desc": ". The substring used to delimit keys and values in the query string."
1801cb0ef41Sopenharmony_ci                },
1811cb0ef41Sopenharmony_ci                {
1821cb0ef41Sopenharmony_ci                  "textRaw": "`options`",
1831cb0ef41Sopenharmony_ci                  "name": "options",
1841cb0ef41Sopenharmony_ci                  "options": [
1851cb0ef41Sopenharmony_ci                    {
1861cb0ef41Sopenharmony_ci                      "textRaw": "`encodeURIComponent` {Function} The function to use when converting URL-unsafe characters to percent-encoding in the query string. **Default:** `querystring.escape()`.",
1871cb0ef41Sopenharmony_ci                      "name": "encodeURIComponent",
1881cb0ef41Sopenharmony_ci                      "type": "Function",
1891cb0ef41Sopenharmony_ci                      "default": "`querystring.escape()`",
1901cb0ef41Sopenharmony_ci                      "desc": "The function to use when converting URL-unsafe characters to percent-encoding in the query string."
1911cb0ef41Sopenharmony_ci                    }
1921cb0ef41Sopenharmony_ci                  ]
1931cb0ef41Sopenharmony_ci                }
1941cb0ef41Sopenharmony_ci              ]
1951cb0ef41Sopenharmony_ci            }
1961cb0ef41Sopenharmony_ci          ],
1971cb0ef41Sopenharmony_ci          "desc": "<p>The <code>querystring.stringify()</code> method produces a URL query string from a\ngiven <code>obj</code> by iterating through the object's \"own properties\".</p>\n<p>It serializes the following types of values passed in <code>obj</code>:\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\" class=\"type\">&lt;bigint&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number[]&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt\" class=\"type\">&lt;bigint[]&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean[]&gt;</a>\nThe numeric values must be finite. Any other input values will be coerced to\nempty strings.</p>\n<pre><code class=\"language-js\">querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });\n// Returns 'foo=bar&#x26;baz=qux&#x26;baz=quux&#x26;corge='\n\nquerystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':');\n// Returns 'foo:bar;baz:qux'\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:</p>\n<pre><code class=\"language-js\">// Assuming gbkEncodeURIComponent function already exists,\n\nquerystring.stringify({ w: '中文', foo: 'bar' }, null, null,\n                      { encodeURIComponent: gbkEncodeURIComponent });\n</code></pre>"
1981cb0ef41Sopenharmony_ci        },
1991cb0ef41Sopenharmony_ci        {
2001cb0ef41Sopenharmony_ci          "textRaw": "`querystring.unescape(str)`",
2011cb0ef41Sopenharmony_ci          "type": "method",
2021cb0ef41Sopenharmony_ci          "name": "unescape",
2031cb0ef41Sopenharmony_ci          "meta": {
2041cb0ef41Sopenharmony_ci            "added": [
2051cb0ef41Sopenharmony_ci              "v0.1.25"
2061cb0ef41Sopenharmony_ci            ],
2071cb0ef41Sopenharmony_ci            "changes": []
2081cb0ef41Sopenharmony_ci          },
2091cb0ef41Sopenharmony_ci          "signatures": [
2101cb0ef41Sopenharmony_ci            {
2111cb0ef41Sopenharmony_ci              "params": [
2121cb0ef41Sopenharmony_ci                {
2131cb0ef41Sopenharmony_ci                  "textRaw": "`str` {string}",
2141cb0ef41Sopenharmony_ci                  "name": "str",
2151cb0ef41Sopenharmony_ci                  "type": "string"
2161cb0ef41Sopenharmony_ci                }
2171cb0ef41Sopenharmony_ci              ]
2181cb0ef41Sopenharmony_ci            }
2191cb0ef41Sopenharmony_ci          ],
2201cb0ef41Sopenharmony_ci          "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>"
2211cb0ef41Sopenharmony_ci        }
2221cb0ef41Sopenharmony_ci      ],
2231cb0ef41Sopenharmony_ci      "type": "module",
2241cb0ef41Sopenharmony_ci      "displayName": "querystring"
2251cb0ef41Sopenharmony_ci    }
2261cb0ef41Sopenharmony_ci  ]
2271cb0ef41Sopenharmony_ci}