Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 711295 of querystring

  • Revision slug: Mozilla/Add-ons/SDK/High-Level_APIs/querystring
  • Revision title: querystring
  • Revision id: 711295
  • Created:
  • Creator: wbamberg
  • Is current revision? No
  • Comment
Tags: 

Revision Content

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.

Revision Source

<div class="note">
 <p>Unstable</p>
</div>
<p><span class="seoSummary">Utility functions for working with query strings.</span></p>
<h2 id="Globals">Globals</h2>
<h3 id="Functions">Functions</h3>
<h4 class="addon-sdk-api-name" id="stringify(fields.2C_separator.2C_assignment)"><code>stringify(fields, separator, assignment)</code></h4>
<p>Serializes an object containing <code>name:value</code> pairs into a query string:</p>
<pre class="brush: js">
querystring.stringify({ foo: 'bar', baz: 4 }); // =&gt; 'foo=bar&amp;baz=4'</pre>
<p>By default <code>'&amp;'</code> and<code>'='</code> are used as separator and assignment characters, but you can override this using additional optional parameters:</p>
<pre class="brush: js">
querystring.stringify({ foo: 'bar', baz: 4 }, ';', ':');  // =&gt; 'foo:bar;baz:4'</pre>
<h5 id="Parameters">Parameters</h5>
<p><strong>fields : object</strong><br />
 The data to convert to a query string.</p>
<p><strong>separator : string</strong><br />
 The string to use as a separator between each <code>name:value</code> pair. By default this is <code>"&amp;"</code>.</p>
<p><strong>assignment : string</strong><br />
 The string to use between each <code>name</code> and its corresponding <code>value</code>. By default this is <code>"="</code>.</p>
<h5 id="Returns">Returns</h5>
<p><strong>string</strong> : The query string.</p>
<h4 class="addon-sdk-api-name" id="parse(querystring.2C_separator.2C_assignment)"><code>parse(querystring, separator, assignment)</code></h4>
<p>Parse a query string into an object containing <code>name:value</code> pairs:</p>
<pre class="brush: js">
querystring.parse('foo=bar&amp;baz=bla') // =&gt;  { foo: 'bar', baz: 'bla' }</pre>
<p>Optionally <code>separator</code> and <code>assignment</code> arguments may be passed to override default <code>'&amp;'</code> and <code>'='</code> characters:</p>
<pre class="brush: js">
<code>querystring.parse('foo:bar</code><code>|baz:bla', '|', ':')  // =&gt; { foo: 'bar', baz: 'bla' }
</code></pre>
<h5 id="Parameters_2">Parameters</h5>
<p><strong>querystring : string</strong><br />
 The query string.</p>
<p><strong>separator : string</strong><br />
 The string to use as a separator between each <code>name:value</code> pair. By default this is <code>"&amp;"</code>.</p>
<p><strong>assignment : string</strong><br />
 The string to use between each <code>name</code> and its corresponding <code>value</code>. By default this is <code>"="</code>.</p>
<h5 id="Returns_2">Returns</h5>
<p><strong>object</strong> : An object containing the components of the query string as <code>name : value</code> pairs.</p>
<h4 class="addon-sdk-api-name" id="escape(query)"><code>escape(query)</code></h4>
<p>The escape function used by <code>stringify</code> to encodes a string safely matching RFC 3986 for <code>application/x-www-form-urlencoded</code>.</p>
<h5 id="Parameters_3">Parameters</h5>
<p><strong>query : string</strong><br />
 The query string to escape.</p>
<h5 id="Returns_3">Returns</h5>
<p><strong>string</strong> : The escaped query string.</p>
<h4 class="addon-sdk-api-name" id="unescape(query)"><code>unescape(query)</code></h4>
<p>The unescape function used by <code>parse</code> to decode a string safely.</p>
<h5 id="Parameters_4">Parameters</h5>
<p><strong>query : string</strong><br />
 An escaped query string.</p>
<h5 id="Returns_4">Returns</h5>
<p><strong>string</strong> : The unescaped string.</p>
Revert to this revision