1 | 'use strict';
|
2 | var defineBuiltIn = require('../internals/define-built-in');
|
3 | var uncurryThis = require('../internals/function-uncurry-this');
|
4 | var toString = require('../internals/to-string');
|
5 | var validateArgumentsLength = require('../internals/validate-arguments-length');
|
6 |
|
7 | var $URLSearchParams = URLSearchParams;
|
8 | var URLSearchParamsPrototype = $URLSearchParams.prototype;
|
9 | var append = uncurryThis(URLSearchParamsPrototype.append);
|
10 | var $delete = uncurryThis(URLSearchParamsPrototype['delete']);
|
11 | var forEach = uncurryThis(URLSearchParamsPrototype.forEach);
|
12 | var push = uncurryThis([].push);
|
13 | var params = new $URLSearchParams('a=1&a=2&b=3');
|
14 |
|
15 | params['delete']('a', 1);
|
16 |
|
17 |
|
18 | params['delete']('b', undefined);
|
19 |
|
20 | if (params + '' !== 'a=2') {
|
21 | defineBuiltIn(URLSearchParamsPrototype, 'delete', function (name /* , value */) {
|
22 | var length = arguments.length;
|
23 | var $value = length < 2 ? undefined : arguments[1];
|
24 | if (length && $value === undefined) return $delete(this, name);
|
25 | var entries = [];
|
26 | forEach(this, function (v, k) {
|
27 | push(entries, { key: k, value: v });
|
28 | });
|
29 | validateArgumentsLength(length, 1);
|
30 | var key = toString(name);
|
31 | var value = toString($value);
|
32 | var index = 0;
|
33 | var dindex = 0;
|
34 | var found = false;
|
35 | var entriesLength = entries.length;
|
36 | var entry;
|
37 | while (index < entriesLength) {
|
38 | entry = entries[index++];
|
39 | if (found || entry.key === key) {
|
40 | found = true;
|
41 | $delete(this, entry.key);
|
42 | } else dindex++;
|
43 | }
|
44 | while (dindex < entriesLength) {
|
45 | entry = entries[dindex++];
|
46 | if (!(entry.key === key && entry.value === value)) append(this, entry.key, entry.value);
|
47 | }
|
48 | }, { enumerable: true, unsafe: true });
|
49 | }
|