Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify constructing URLSearchParams #175

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ steps:
<h3 id=interface-urlsearchparams>Interface {{URLSearchParams}}</h3>

<pre class=idl>
[Constructor(optional (USVString or URLSearchParams) init = ""),
[Constructor(optional (sequence&lt;sequence&lt;USVString>> or record&lt;USVString, USVString> or USVString) init = ""),
Exposed=(Window,Worker)]
interface URLSearchParams {
void append(USVString name, USVString value);
Expand All @@ -2718,6 +2718,14 @@ interface URLSearchParams {
};
</pre>

<div class=example id=example-constructing-urlsearchparams>
<p>Constructing and stringifying a {{URLSearchParams}} object is fairly straightforward:

<pre><code class="lang-javascript">
let params = new URLSearchParams({key: 730d67})
params.toString() // key=730d67</code></pre>
</div>

<p>A {{URLSearchParams}} object has an associated
<dfn export for=URLSearchParams id=concept-urlsearchparams-list>list</dfn> of name-value pairs,
which is initially empty.
Expand All @@ -2732,14 +2740,25 @@ initially null.
<ol>
<li><p>Let <var>query</var> be a new {{URLSearchParams}} object.

<li><p>If <var>init</var> is a string, set <var>query</var>'s
<a for=URLSearchParams>list</a> to the result of
<a lt='urlencoded string parser'>parsing</a> <var>init</var>.
<li>
<p>If <var>init</var> is a <a>sequence</a>, then for each <var>pair</var> in <var>init</var>:

<li><p>If <var>init</var> is a {{URLSearchParams}} object, set <var>query</var>'s
<a for=URLSearchParams>list</a> to a copy of <var>init</var>'s
<ol>
<li><p>If <var>pair</var> does not contain exactly two items, then <a>throw</a> a {{TypeError}}.

<li><p>Append a new name-value pair whose name is <var>pair</var>'s first item, and value is
<var>pair</var>'s second item, to <var>query</var>'s <a for=URLSearchParams>list</a>.
</ol>

<li><p>Otherwise, if <var>init</var> is a <a>record</a>, then for each <a for=record>mapping</a>
(<var>name</var>, <var>value</var>) in <var>init</var>, append a new name-value pair whose name is
<var>name</var> and value is <var>value</var>, to <var>query</var>'s
<a for=URLSearchParams>list</a>.

<li><p>Otherwise, <var>init</var> is a string, then set <var>query</var>'s
<a for=URLSearchParams>list</a> to the result of
<a lt='urlencoded string parser'>parsing</a> <var>init</var>.

<li><p>Return <var>query</var>.
</ol>

Expand Down Expand Up @@ -2885,6 +2904,7 @@ James Ross,
Joshua Bell,
Jxck,
Kevin Grandon,
Kornel Lesiński,
Larry Masinter,
Leif Halvard Silli,
Mark Davis,
Expand Down