querystring

We are planning to deprecate the use by Firefox add-ons of the techniques described in this document.

Don't use these techniques to develop new add-ons. Use WebExtensions instead.

If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions instead.

Add-ons developed using these techniques might not work with multiprocess Firefox (e10s), which is already the default in Firefox Nightly and Firefox Developer Edition, and will soon be the default in Beta and Release versions of Firefox. We have documentation on making your add-ons multiprocess-compatible, but it will be more future-proof for you to migrate to WebExtensions.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

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,