Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1e20b05

Browse filesBrowse files
jasnelltargos
authored andcommitted
url: implement URLSearchParams size getter
Refs: whatwg/url#734 PR-URL: #46308 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent bd5ef38 commit 1e20b05
Copy full SHA for 1e20b05

File tree

Expand file treeCollapse file tree

3 files changed

+23
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/url.md‎

Copy file name to clipboardExpand all lines: doc/api/url.md
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,14 @@ console.log(params.toString());
940940
// Prints foo=def&abc=def&xyz=opq
941941
```
942942

943+
#### `urlSearchParams.size`
944+
945+
<!-- YAML
946+
added: REPLACEME
947+
-->
948+
949+
The total number of parameter entries.
950+
943951
#### `urlSearchParams.sort()`
944952

945953
<!-- YAML
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ class URLSearchParams {
268268
return `${this.constructor.name} {}`;
269269
}
270270

271+
get size() {
272+
if (!isURLSearchParams(this))
273+
throw new ERR_INVALID_THIS('URLSearchParams');
274+
return this[searchParams].length / 2;
275+
}
276+
271277
append(name, value) {
272278
if (!isURLSearchParams(this))
273279
throw new ERR_INVALID_THIS('URLSearchParams');
@@ -511,6 +517,7 @@ ObjectDefineProperties(URLSearchParams.prototype, {
511517
getAll: kEnumerableProperty,
512518
has: kEnumerableProperty,
513519
set: kEnumerableProperty,
520+
size: kEnumerableProperty,
514521
sort: kEnumerableProperty,
515522
entries: kEnumerableProperty,
516523
forEach: kEnumerableProperty,
Collapse file

‎test/parallel/test-whatwg-url-properties.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-properties.js
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ const { URL, URLSearchParams, format } = require('url');
6565
testMethod(URLSearchParams.prototype, name, methodName);
6666
});
6767

68+
{
69+
const params = new URLSearchParams();
70+
params.append('a', 'b');
71+
params.append('a', 'c');
72+
params.append('b', 'c');
73+
assert.strictEqual(params.size, 3);
74+
}
75+
6876
function stringifyName(name) {
6977
if (typeof name === 'symbol') {
7078
const { description } = name;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.