Re: [whatwg/url] Add URLSearchParams.prototype.sort() (#199)

annevk commented on this pull request.



> +
+<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)).sort();</code></pre>

Thanks, I opted for fixing the example. Might change if we fix #90 as requested I suppose.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/pull/199

Received on Sunday, 15 January 2017 06:16:11 UTC