{ "type": "module", "source": "doc/api/querystring.md", "modules": [ { "textRaw": "Query String", "name": "querystring", "introduced_in": "v0.10.0", "stability": 2, "stabilityText": "Stable", "desc": "

The querystring module provides utilities for parsing and formatting URL\nquery strings. It can be accessed using:

\n
const querystring = require('querystring');\n
", "methods": [ { "textRaw": "querystring.decode()", "type": "method", "name": "decode", "meta": { "added": [ "v0.1.99" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "

The querystring.decode() function is an alias for querystring.parse().

" }, { "textRaw": "querystring.encode()", "type": "method", "name": "encode", "meta": { "added": [ "v0.1.99" ], "changes": [] }, "signatures": [ { "params": [] } ], "desc": "

The querystring.encode() function is an alias for querystring.stringify().

" }, { "textRaw": "querystring.escape(str)", "type": "method", "name": "escape", "meta": { "added": [ "v0.1.25" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`str` {string}", "name": "str", "type": "string" } ] } ], "desc": "

The querystring.escape() method performs URL percent-encoding on the given\nstr in a manner that is optimized for the specific requirements of URL\nquery strings.

\n

The querystring.escape() method is used by querystring.stringify() 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 querystring.escape to an alternative function.

" }, { "textRaw": "querystring.parse(str[, sep[, eq[, options]]])", "type": "method", "name": "parse", "meta": { "added": [ "v0.1.25" ], "changes": [ { "version": "v8.0.0", "pr-url": "https://github.com/nodejs/node/pull/10967", "description": "Multiple empty entries are now parsed correctly (e.g. `&=&=`)." }, { "version": "v6.0.0", "pr-url": "https://github.com/nodejs/node/pull/6055", "description": "The returned object no longer inherits from `Object.prototype`." }, { "version": "v6.0.0, v4.2.4", "pr-url": "https://github.com/nodejs/node/pull/3807", "description": "The `eq` parameter may now have a length of more than `1`." } ] }, "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. **Default:** `'&'`.", "name": "sep", "type": "string", "default": "`'&'`", "desc": "The substring used to delimit key and value pairs in the query string.", "optional": true }, { "textRaw": "`eq` {string}. The substring used to delimit keys and values in the query string. **Default:** `'='`.", "name": "eq", "type": "string", "default": "`'='`", "desc": ". The substring used to delimit keys and values in the query string.", "optional": true }, { "textRaw": "`options` {Object}", "name": "options", "type": "Object", "options": [ { "textRaw": "`decodeURIComponent` {Function} The function to use when decoding percent-encoded characters in the query string. **Default:** `querystring.unescape()`.", "name": "decodeURIComponent", "type": "Function", "default": "`querystring.unescape()`", "desc": "The function to use when decoding percent-encoded characters in the query string." }, { "textRaw": "`maxKeys` {number} Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations. **Default:** `1000`.", "name": "maxKeys", "type": "number", "default": "`1000`", "desc": "Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations." } ], "optional": true } ] } ], "desc": "

The querystring.parse() method parses a URL query string (str) into a\ncollection of key and value pairs.

\n

For example, the query string 'foo=bar&abc=xyz&abc=123' is parsed into:

\n\n
{\n  foo: 'bar',\n  abc: ['xyz', '123']\n}\n
\n

The object returned by the querystring.parse() method does not\nprototypically inherit from the JavaScript Object. This means that typical\nObject methods such as obj.toString(), obj.hasOwnProperty(), and others\nare not defined and will not work.

\n

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 decodeURIComponent option will need to be specified:

\n
// Assuming gbkDecodeURIComponent function already exists...\n\nquerystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null,\n                  { decodeURIComponent: gbkDecodeURIComponent });\n
" }, { "textRaw": "querystring.stringify(obj[, sep[, eq[, options]]])", "type": "method", "name": "stringify", "meta": { "added": [ "v0.1.25" ], "changes": [] }, "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. **Default:** `'&'`.", "name": "sep", "type": "string", "default": "`'&'`", "desc": "The substring used to delimit key and value pairs in the query string.", "optional": true }, { "textRaw": "`eq` {string}. The substring used to delimit keys and values in the query string. **Default:** `'='`.", "name": "eq", "type": "string", "default": "`'='`", "desc": ". The substring used to delimit keys and values in the query string.", "optional": true }, { "textRaw": "`options`", "name": "options", "options": [ { "textRaw": "`encodeURIComponent` {Function} The function to use when converting URL-unsafe characters to percent-encoding in the query string. **Default:** `querystring.escape()`.", "name": "encodeURIComponent", "type": "Function", "default": "`querystring.escape()`", "desc": "The function to use when converting URL-unsafe characters to percent-encoding in the query string." } ], "optional": true } ] } ], "desc": "

The querystring.stringify() method produces a URL query string from a\ngiven obj by iterating through the object's \"own properties\".

\n

It serializes the following types of values passed in obj:\n<string> | <number> | <boolean> | <string[]> | <number[]> | <boolean[]>\nAny other input values will be coerced to empty strings.

\n
querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });\n// returns 'foo=bar&baz=qux&baz=quux&corge='\n\nquerystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':');\n// returns 'foo:bar;baz:qux'\n
\n

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\nencodeURIComponent option will need to be specified:

\n
// Assuming gbkEncodeURIComponent function already exists,\n\nquerystring.stringify({ w: '中文', foo: 'bar' }, null, null,\n                      { encodeURIComponent: gbkEncodeURIComponent });\n
" }, { "textRaw": "querystring.unescape(str)", "type": "method", "name": "unescape", "meta": { "added": [ "v0.1.25" ], "changes": [] }, "signatures": [ { "params": [ { "textRaw": "`str` {string}", "name": "str", "type": "string" } ] } ], "desc": "

The querystring.unescape() method performs decoding of URL percent-encoded\ncharacters on the given str.

\n

The querystring.unescape() method is used by querystring.parse() 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 querystring.unescape to an alternative function.

\n

By default, the querystring.unescape() method will attempt to use the\nJavaScript built-in decodeURIComponent() method to decode. If that fails,\na safer equivalent that does not throw on malformed URLs will be used.

" } ], "type": "module", "displayName": "querystring" } ] }