node:querystring
Node-compatible URL query string parsing and serialization (node:querystring).
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
import ... from "node:querystring"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature:
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { parse, stringify } from "node:querystring";
console.log(parse("foo=bar&tag=a&tag=b"));console.log(stringify({ foo: "bar", tag: ["a", "b"] }));API Symbols
Functions (4)
Interfaces (2)
Type Aliases (2)
Functions
Section titled “Functions”export function parse(
str: string,
sep?: string,
eq?: string,
options?: ParseOptions,
): ParsedUrlQuery;
Parse a URL query string str into a key/value object.
Parameters
| Name | Type | Description |
|---|---|---|
str | string | Query string to parse. |
sep optional | string | Pair delimiter substring (default "&"). |
eq optional | string | Key/value assignment delimiter substring (default "="). |
options optional | ParseOptions | Optional maxKeys and custom decodeURIComponent. |
Returns
ParsedUrlQuery — Parsed query object.stringify
Section titled “stringify”export function stringify(
obj?: ParsedUrlQueryInput,
sep?: string,
eq?: string,
options?: StringifyOptions,
): string;
Serialize obj into a URL query string.
Parameters
| Name | Type | Description |
|---|---|---|
obj optional | ParsedUrlQueryInput | Object of query parameters to serialize. |
sep optional | string | Pair delimiter substring (default "&"). |
eq optional | string | Key/value assignment delimiter substring (default "="). |
options optional | StringifyOptions | Optional custom encodeURIComponent. |
Returns
string — Serialized query string.escape
Section titled “escape”export function escape(str: string): string;
Percent-encode str for use in a URL query string.
Parameters
| Name | Type | Description |
|---|---|---|
str | string | String to percent-encode. |
Returns
string — Percent-encoded string.unescape
Section titled “unescape”export function unescape(str: string): string;
Decode percent-encoded sequences and "+" spaces in str.
Parameters
| Name | Type | Description |
|---|---|---|
str | string | Percent-encoded string to decode. |
Returns
string — Decoded string.Interfaces
Section titled “Interfaces”ParseOptions
Section titled “ParseOptions”export interface ParseOptions {
maxKeys?: number;
decodeURIComponent?: (str: string) => string;
}
Options accepted by parse() and decode().
Properties
| Property | Type | Description | Since |
|---|---|---|---|
maxKeys optional | number | Maximum number of keys to parse (0 for unlimited, default 1000). | v0.0.0-alpha.2 |
decodeURIComponent optional | (str: string) => string | Custom percent-decoding function (defaults to unescape). | v0.0.0-alpha.2 |
StringifyOptions
Section titled “StringifyOptions”export interface StringifyOptions {
encodeURIComponent?: (str: string) => string;
}
Options accepted by stringify() and encode().
Properties
| Property | Type | Description | Since |
|---|---|---|---|
encodeURIComponent optional | (str: string) => string | Custom percent-encoding function (defaults to escape). | v0.0.0-alpha.2 |
Type Aliases
Section titled “Type Aliases”ParsedUrlQuery
Section titled “ParsedUrlQuery”export type ParsedUrlQuery = Record<string, string | string[]>;
Parsed query object returned by parse() and decode().
ParsedUrlQueryInput
Section titled “ParsedUrlQueryInput”export type ParsedUrlQueryInput = Record<
string,
string | number | boolean | readonly (string | number | boolean)[] | null | undefined
>;
Input object accepted by stringify() and encode().
Constants
Section titled “Constants”decode
Section titled “decode”export const decode: typeof parse;
Alias for parse.
encode
Section titled “encode”export const encode: typeof stringify;
Alias for stringify.
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Parse a URL query string. @since 0.0.0-alpha.2 */
parse: typeof parse;
/** Serialize an object into a URL query string. @since 0.0.0-alpha.2 */
stringify: typeof stringify;
/** Percent-encode a query string component. @since 0.0.0-alpha.2 */
escape: typeof escape;
/** Decode a percent-encoded query string component. @since 0.0.0-alpha.2 */
unescape: typeof unescape;
/** Alias for `parse`. @since 0.0.0-alpha.2 */
decode: typeof decode;
/** Alias for `stringify`. @since 0.0.0-alpha.2 */
encode: typeof encode;
};
export default _default;
Default export object providing { parse, stringify, escape, unescape, decode, encode }.
