url icon indicating copy to clipboard operation
url copied to clipboard

[proposal] Enhanced the ability for multiple same-name-parameters to the URLSearchParams: .has() and .delete()

Open LIXiangChen opened this issue 3 years ago • 2 comments

The proposal is fully compatible with the existing scheme. There has a similar idea https://github.com/whatwg/url/issues/335, but not exactly same.


.has()

Syntax

URLSearchParams.has(name, [value])

The changes

  1. Added optional second parameter

.delete()

Syntax

URLSearchParams.delete(name, [value])

Return value Number of parameters deleted, greater than or equal to 0.

The changes

  1. Added optional second parameter
  2. Added return value, this is very useful

LIXiangChen avatar Jan 04 '22 04:01 LIXiangChen

https://github.com/whatwg/url/issues/335#issuecomment-623477090 applies here as well:

What would help in driving this forward is some indication that this is a common need (e.g., StackOverflow questions) and is being addressed in libraries (with the proposed semantics). That might make this a more compelling case to implementers.

annevk avatar Jan 04 '22 08:01 annevk

Not sure if we need a .has(key, value), since it's equivalent to .getAll(key).include(value). The possibility of adding a return value to delete is interesting though, since Map.prototype.delete returns a boolean for whether an entry was deleted.

TimothyGu avatar Jan 05 '22 01:01 TimothyGu

@LIXiangChen can you elaborate on when you would use the return value?

annevk avatar Dec 09 '22 12:12 annevk