querystring

Unstable

Utility functions for working with query strings.

Globals

Functions

stringify(fields, separator, assignment)

Serializes an object containing name:value pairs into a query string:

querystring.stringify({ foo: 'bar', baz: 4 }); // => 'foo=bar&baz=4'

By default '&' and'=' are used as separator and assignment characters, but you can override this using additional optional parameters:

querystring.stringify({ foo: 'bar', baz: 4 }, ';', ':');  // => 'foo:bar;baz:4'
Parameters

fields : object
The data to convert to a query string.

separator : string
The string to use as a separator between each name:value pair. By default this is "&".

assignment : string
The string to use between each name and its corresponding value. By default this is "=".

Returns

string : The query string.

parse(querystring, separator, assignment)

Parse a query string into an object containing name:value pairs:

querystring.parse('foo=bar&baz=bla') // =>  { foo: 'bar', baz: 'bla' }

Optionally separator and assignment arguments may be passed to override default '&' and '=' characters:

querystring.parse('foo:bar|baz:bla', '|', ':')  // => { foo: 'bar', baz: 'bla' }
Parameters

querystring : string
The query string.

separator : string
The string to use as a separator between each name:value pair. By default this is "&".

assignment : string
The string to use between each name and its corresponding value. By default this is "=".

Returns

object : An object containing the components of the query string as name : value pairs.

escape(query)

The escape function used by stringify to encodes a string safely matching RFC 3986 for application/x-www-form-urlencoded.

Parameters

query : string
The query string to escape.

Returns

string : The escaped query string.

unescape(query)

The unescape function used by parse to decode a string safely.

Parameters

query : string
An escaped query string.

Returns

string : The unescaped string.

Document Tags and Contributors

Tags: 
 Contributors to this page: wbamberg
 Last updated by: wbamberg,