-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
value
argument of URLSearchParams.prototype.{ has, delete }
- Loading branch information
Showing
14 changed files
with
167 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3239,7 +3239,7 @@ queueMicrotask(() => console.log('called as microtask')); | |
``` | ||
#### `URL` and `URLSearchParams`[⬆](#index) | ||
[`URL` standard](https://url.spec.whatwg.org/) implementation. Modules [`web.url`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.js), [`web.url.can-parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.can-parse.js), [`web.url.to-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.to-json.js), [`web.url-search-params`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.js), [`web.url-search-params.size`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.size.js). | ||
[`URL` standard](https://url.spec.whatwg.org/) implementation. Modules [`web.url`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.js), [`web.url.can-parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.can-parse.js), [`web.url.to-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url.to-json.js), [`web.url-search-params`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.js), [`web.url-search-params.delete`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.delete.js), [`web.url-search-params.has`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.has.js), [`web.url-search-params.size`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.url-search-params.size.js). | ||
```js | ||
class URL { | ||
constructor(url: string, base?: string); | ||
|
@@ -3263,10 +3263,10 @@ class URL { | |
class URLSearchParams { | ||
constructor(params?: string | Iterable<[key, value]> | Object); | ||
append(name: string, value: string): void; | ||
delete(name: string): void; | ||
delete(name: string, value?: string): void; | ||
get(name: string): string | void; | ||
getAll(name: string): Array<string>; | ||
has(name: string): boolean; | ||
has(name: string, value?: string): boolean; | ||
set(name: string, value: string): void; | ||
sort(): void; | ||
toString(): string; | ||
|
@@ -3286,7 +3286,7 @@ core-js(-pure)/stable|actual|full/url/can-parse | |
core-js/stable|actual|full/url/to-json | ||
core-js(-pure)/stable|actual|full/url-search-params | ||
``` | ||
[*Examples*](https://tinyurl.com/2ovt23zn): | ||
[*Examples*](https://tinyurl.com/2j35uor6): | ||
```js | ||
URL.canParse('https://login:[email protected]:8080/?a=1&b=2&a=3&c=4#fragment'); // => true | ||
URL.canParse('https'); // => false | ||
|
@@ -3322,16 +3322,21 @@ const params = new URLSearchParams('?a=1&b=2&a=3'); | |
|
||
params.append('c', 4); | ||
params.append('a', 2); | ||
params.delete('a', 1); | ||
params.sort(); | ||
|
||
console.log(params.size); // => 5 | ||
console.log(params.size); // => 4 | ||
|
||
for (let [key, value] of params) { | ||
console.log(key); // => 'a', 'a', 'a', 'b', 'c' | ||
console.log(value); // => '1', '3', '2', '2', '4' | ||
console.log(key); // => 'a', 'a', 'b', 'c' | ||
console.log(value); // => '3', '2', '2', '4' | ||
} | ||
|
||
console.log(params.toString()); // => 'a=1&a=3&a=2&b=2&c=4' | ||
console.log(params.has('a')); // => true | ||
console.log(params.has('a', 3)); // => true | ||
console.log(params.has('a', 4)); // => false | ||
|
||
console.log(params.toString()); // => 'a=3&a=2&b=2&c=4' | ||
``` | ||
##### Caveats when using `URL` and `URLSearchParams`:[⬆](#index) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var defineBuiltIn = require('../internals/define-built-in'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var toString = require('../internals/to-string'); | ||
var validateArgumentsLength = require('../internals/validate-arguments-length'); | ||
|
||
var URLSearchParams = getBuiltIn('URLSearchParams'); | ||
var URLSearchParamsPrototype = URLSearchParams.prototype; | ||
var append = uncurryThis(URLSearchParamsPrototype.append); | ||
var $delete = uncurryThis(URLSearchParamsPrototype['delete']); | ||
var forEach = uncurryThis(URLSearchParamsPrototype.forEach); | ||
var push = uncurryThis([].push); | ||
var params = new URLSearchParams('a=1&a=2'); | ||
|
||
params['delete']('a', 1); | ||
|
||
if (params + '' !== 'a=2') { | ||
defineBuiltIn(URLSearchParamsPrototype, 'delete', function (name /* , value */) { | ||
var length = arguments.length; | ||
var $value = length < 2 ? undefined : arguments[1]; | ||
if (length && $value === undefined) return $delete(this, name); | ||
var entries = []; | ||
forEach(this, function (v, k) { // also validates `this` | ||
push(entries, { key: k, value: v }); | ||
}); | ||
validateArgumentsLength(length, 1); | ||
var key = toString(name); | ||
var value = toString($value); | ||
var index = 0; | ||
var entriesLength = entries.length; | ||
while (index < entriesLength) { | ||
$delete(this, entries[index++].key); | ||
} | ||
index = 0; | ||
while (index < entriesLength) { | ||
var entry = entries[index++]; | ||
if (!(entry.key === key && entry.value === value)) append(this, entry.key, entry.value); | ||
} | ||
}, { enumerable: true, unsafe: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
var getBuiltIn = require('../internals/get-built-in'); | ||
var defineBuiltIn = require('../internals/define-built-in'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var toString = require('../internals/to-string'); | ||
var validateArgumentsLength = require('../internals/validate-arguments-length'); | ||
|
||
var URLSearchParams = getBuiltIn('URLSearchParams'); | ||
var URLSearchParamsPrototype = URLSearchParams.prototype; | ||
var getAll = uncurryThis(URLSearchParamsPrototype.getAll); | ||
var $has = uncurryThis(URLSearchParamsPrototype.has); | ||
var params = new URLSearchParams('a=1'); | ||
|
||
if (params.has('a', 2)) { | ||
defineBuiltIn(URLSearchParamsPrototype, 'has', function has(name /* , value */) { | ||
var length = arguments.length; | ||
var $value = length < 2 ? undefined : arguments[1]; | ||
if (length && $value === undefined) return $has(this, name); | ||
var values = getAll(this, name); // also validates `this` | ||
validateArgumentsLength(length, 1); | ||
var value = toString($value); | ||
var index = 0; | ||
while (index < values.length) { | ||
if (values[index++] === value) return true; | ||
} return false; | ||
}, { enumerable: true, unsafe: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
// https://github.com/jasnell/proposal-url | ||
require('../modules/web.url'); | ||
require('../modules/web.url.can-parse'); | ||
require('../modules/web.url.to-json'); | ||
require('../modules/web.url-search-params'); | ||
require('../modules/web.url-search-params.size'); | ||
require('../web/url'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
require('./url-search-params'); | ||
require('../modules/web.url'); | ||
require('../modules/web.url.can-parse'); | ||
require('../modules/web.url.to-json'); | ||
require('../modules/web.url-search-params'); | ||
require('../modules/web.url-search-params.size'); | ||
var path = require('../internals/path'); | ||
|
||
module.exports = path.URL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters