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

Add URLSearchParams.prototype.sort() #199

Merged
merged 6 commits into from
Jan 18, 2017
Merged
Changes from 4 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
44 changes: 40 additions & 4 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,9 @@ interface URLSearchParams {
sequence<USVString> getAll(USVString name);
boolean has(USVString name);
void set(USVString name, USVString value);

void sort();

iterable<USVString, USVString>;
stringifier;
};
Expand Down Expand Up @@ -2843,6 +2846,11 @@ method, when invoked, must return the value of the first name-value pair whose n
method, when invoked, must return the values of all name-value pairs whose name is <var>name</var>,
in <a for=URLSearchParams>list</a>, in list order, and the empty sequence otherwise.

<p>The
<dfn method for=URLSearchParams><code>has(<var>name</var>)</code></dfn>
method, when invoked, must return true if there is a name-value pair whose name is <var>name</var>
in <a for=URLSearchParams>list</a>, and false otherwise.

<p>The
<dfn method for=URLSearchParams><code>set(<var>name</var>, <var>value</var>)</code></dfn>
method, when invoked, must run these steps:
Expand All @@ -2858,10 +2866,37 @@ method, when invoked, must run these steps:
<li><p>Run the <a for=URLSearchParams>update steps</a>.
</ol>

<p>The
<dfn method for=URLSearchParams><code>has(<var>name</var>)</code></dfn>
method, when invoked, must return true if there is a name-value pair whose name is <var>name</var>
in <a for=URLSearchParams>list</a>, and false otherwise.
<hr>

<div class=example id=example-searchparams-sort>
<p>It can be useful to sort the name-value pairs in a {{SearchParams}} object, in particular to
increase cache hits. This can be accomplished simply through invoking the {{SearchParams/sort()}}
method:

<pre><code class=lang-javascript>
const url = new URL("https://example.org/?q=🏳️‍🌈&amp;key=e1f7bc78");
url.searchParams.sort();
url.search; // "?key=e1f7bc78&amp;q=%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88"</code></pre>

<p>To avoid altering the original input, e.g., for comparison purposes, construct a new
{{SearchParams}} object:

<pre><code class=lang-javascript>
const sorted = new URLSearchParams(url.search)
sorted.sort()</code></pre>
</div>

<p>The <dfn method for=URLSearchParams><code>sort()</code></dfn> method, when invoked, must run
these steps:

<ol>
<li><p>Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of
code units. The relative order between name-value pairs with equal names must be preserved.

<li><p>Run the <a for=URLSearchParams>update steps</a>.
</ol>

<hr>

<p>The <a>value pairs to iterate over</a> are the
<a for=URLSearchParams>list</a> name-value pairs with the key being
Expand Down Expand Up @@ -2969,6 +3004,7 @@ Tab Atkins,
Tantek Çelik,
Tim Berners-Lee,
簡冠庭 (Tim Guan-tin Chien),
Timothy Gu,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please attribute to me as

Tiancheng "Timothy" Gu

which contains my legal name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, should have asked.

Titi_Alone,
Tomek Wytrębowicz,
Valentin Gosu,
Expand Down