@shgysk8zer0/polyfills 0.3.14 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +5 -1
- package/abort.js +166 -168
- package/all.min.js +11 -11
- package/all.min.js.map +1 -1
- package/array.js +1 -1
- package/assets/dedent.js +172 -0
- package/assets/url-pattern.cjs +4 -0
- package/assets/url-pattern.js +22 -0
- package/node.js +19 -0
- package/node.min.js +6 -0
- package/node.min.js.map +1 -0
- package/package.json +16 -15
- package/rollup.config.js +36 -8
- package/string.js +1 -1
- package/url.js +5 -0
- package/weakMap.js +21 -25
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [v0.4.1] - 2024-08-24
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Add [`URLPattern`](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) via [`urlpattern-polyfill`](https://github.com/kenchris/urlpattern-polyfill)
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Fix error in `Uint8Array.prototype.toHex()`
|
|
16
|
+
|
|
17
|
+
## [v0.4.0] - 2024-08-19
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- Add node version of polyfills (`node.js` and `node.min.js`)
|
|
21
|
+
- Add some automated tests (`test/node.js`)
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- Create local module from `string-dedent` instead of having as a dependency
|
|
25
|
+
- Update `rollup.config.js` to create all needed bundles
|
|
26
|
+
|
|
9
27
|
## [v0.3.14] - 2024-07-16
|
|
10
28
|
|
|
11
29
|
### Fixed
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ You can use a CDN to access the library. Add the following script tag to your
|
|
|
40
40
|
HTML file to load the latest version:
|
|
41
41
|
|
|
42
42
|
```html
|
|
43
|
-
<script src="https://unpkg.com/@shgysk8zer0/polyfills/all.min.js"></script>
|
|
43
|
+
<script src="https://unpkg.com/@shgysk8zer0/polyfills[@version]/all.min.js"></script>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
#### With version and SRI
|
|
@@ -57,6 +57,10 @@ the following command to install the library:
|
|
|
57
57
|
```bash
|
|
58
58
|
npm install @shgysk8zer0/polyfills
|
|
59
59
|
```
|
|
60
|
+
> [!Note]
|
|
61
|
+
> If using this polyfills package in a node environment, you want to use `node.js` instead
|
|
62
|
+
> of `all.js`. The node version omits polyfills that do not make sense in NodeJS, such as DOM.
|
|
63
|
+
> Simply using `import '@shgysk8zer0/polyfills'` or `require('@shgysk8zer0/polyfills')` should work.
|
|
60
64
|
|
|
61
65
|
### Git Submodule
|
|
62
66
|
|
package/abort.js
CHANGED
|
@@ -1,194 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
this.onabort.call(this, event);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get aborted() {
|
|
47
|
-
return this[symbols.aborted];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get onabort() {
|
|
51
|
-
return this[symbols.onabort];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
set onabort(value) {
|
|
55
|
-
if (value instanceof Function) {
|
|
56
|
-
this[symbols.onabort] = value;
|
|
57
|
-
} else {
|
|
58
|
-
this[symbols.onabort] = null;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
if (! ('AbortSignal' in globalThis)) {
|
|
4
|
+
const symbols = {
|
|
5
|
+
signal: Symbol('signal'),
|
|
6
|
+
aborted: Symbol('aborted'),
|
|
7
|
+
reason: Symbol('reason'),
|
|
8
|
+
onabort: Symbol('onabort'),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
globalThis.AbortError = class AbortError extends Error {};
|
|
12
|
+
|
|
13
|
+
globalThis.AbortSignal = class AbortSignal extends EventTarget {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
Object.defineProperties(this,{
|
|
18
|
+
[symbols.aborted]: {
|
|
19
|
+
enumerable: false,
|
|
20
|
+
writable: true,
|
|
21
|
+
configurable: false,
|
|
22
|
+
value: false,
|
|
23
|
+
},
|
|
24
|
+
[symbols.reason]: {
|
|
25
|
+
enumerable: false,
|
|
26
|
+
writable: true,
|
|
27
|
+
configurable: false,
|
|
28
|
+
value: undefined,
|
|
29
|
+
},
|
|
30
|
+
[symbols.onabort]: {
|
|
31
|
+
enumerable: false,
|
|
32
|
+
writable: true,
|
|
33
|
+
configurable: false,
|
|
34
|
+
value: null,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.addEventListener('abort', event => {
|
|
39
|
+
if (this.onabort instanceof Function) {
|
|
40
|
+
this.onabort.call(this, event);
|
|
59
41
|
}
|
|
60
|
-
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
61
44
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
45
|
+
get aborted() {
|
|
46
|
+
return this[symbols.aborted];
|
|
47
|
+
}
|
|
65
48
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
49
|
+
get onabort() {
|
|
50
|
+
return this[symbols.onabort];
|
|
51
|
+
}
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
set onabort(value) {
|
|
54
|
+
if (value instanceof Function) {
|
|
55
|
+
this[symbols.onabort] = value;
|
|
56
|
+
} else {
|
|
57
|
+
this[symbols.onabort] = null;
|
|
77
58
|
}
|
|
78
|
-
}
|
|
59
|
+
}
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
61
|
+
get reason() {
|
|
62
|
+
return this[symbols.reason];
|
|
63
|
+
}
|
|
84
64
|
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
throwIfAborted() {
|
|
66
|
+
if (this.aborted) {
|
|
67
|
+
throw this.reason;
|
|
87
68
|
}
|
|
69
|
+
}
|
|
88
70
|
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
static abort(reason = new DOMException('Operation aborted')) {
|
|
72
|
+
const signal = new AbortSignal();
|
|
73
|
+
signal[symbols.aborted] = true;
|
|
74
|
+
signal[symbols.reason] = reason;
|
|
75
|
+
return signal;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
91
78
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
79
|
+
globalThis.AbortController = class AbortController {
|
|
80
|
+
constructor() {
|
|
81
|
+
this[symbols.signal] = new AbortSignal();
|
|
82
|
+
}
|
|
100
83
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
get signal() {
|
|
85
|
+
return this[symbols.signal];
|
|
86
|
+
}
|
|
104
87
|
|
|
105
|
-
|
|
106
|
-
const
|
|
88
|
+
abort(reason = new DOMException('Operation aborted')) {
|
|
89
|
+
const signal = this.signal;
|
|
107
90
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
AbortSignal.abort = function abort(reason = new DOMException('Operation aborted')) {
|
|
115
|
-
const controller = new AbortController();
|
|
116
|
-
controller.abort(reason);
|
|
117
|
-
return controller.reason;
|
|
118
|
-
};
|
|
91
|
+
if (! signal.aborted) {
|
|
92
|
+
signal[symbols.aborted] = true;
|
|
93
|
+
signal[symbols.reason] = reason;
|
|
94
|
+
signal.dispatchEvent(new Event('abort'));
|
|
95
|
+
}
|
|
119
96
|
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
120
99
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
get: function() {
|
|
125
|
-
if (reasons.has(this)) {
|
|
126
|
-
return reasons.get(this);
|
|
127
|
-
} else {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
100
|
+
if (! ('reason' in AbortSignal.prototype)) {
|
|
101
|
+
const reasons = new WeakMap();
|
|
102
|
+
const abort = AbortController.prototype.abort;
|
|
132
103
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
abort.call(this);
|
|
136
|
-
};
|
|
137
|
-
}
|
|
104
|
+
if (AbortSignal.abort instanceof Function) {
|
|
105
|
+
const staticAbort = AbortSignal.abort;
|
|
138
106
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
107
|
+
AbortSignal.abort = function(reason = new DOMException('Operation aborted')) {
|
|
108
|
+
const signal = staticAbort();
|
|
109
|
+
reasons.set(signal, reason);
|
|
110
|
+
return signal;
|
|
144
111
|
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
throw new TypeError('At least one 1 argument required but only 0 passed');
|
|
151
|
-
} else if (! Number.isFinite(ms)) {
|
|
152
|
-
throw new TypeError('Argument 1 is not a finite value, so it is out of range for unsigned long long.');
|
|
153
|
-
} else if (ms < 0) {
|
|
154
|
-
throw new TypeError('Argument 1 is out of range for unsigned long long.');
|
|
155
|
-
} else {
|
|
156
|
-
const controller = new AbortController();
|
|
157
|
-
setTimeout(() => controller.abort(new DOMException('The operation timed out.')), ms);
|
|
158
|
-
return controller.signal;
|
|
159
|
-
}
|
|
112
|
+
} else {
|
|
113
|
+
AbortSignal.abort = function abort(reason = new DOMException('Operation aborted')) {
|
|
114
|
+
const controller = new AbortController();
|
|
115
|
+
controller.abort(reason);
|
|
116
|
+
return controller.reason;
|
|
160
117
|
};
|
|
161
118
|
}
|
|
162
119
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
throw new TypeError('Expected an array of signals');
|
|
120
|
+
Object.defineProperty(AbortSignal.prototype, 'reason', {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
get: function() {
|
|
124
|
+
if (reasons.has(this)) {
|
|
125
|
+
return reasons.get(this);
|
|
126
|
+
} else {
|
|
127
|
+
return undefined;
|
|
172
128
|
}
|
|
173
|
-
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
AbortController.prototype.abort = function(reason = new DOMException('Operation aborted')) {
|
|
133
|
+
reasons.set(this.signal, reason);
|
|
134
|
+
abort.call(this);
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (! (AbortSignal.prototype.throwIfAborted instanceof Function)) {
|
|
139
|
+
AbortSignal.prototype.throwIfAborted = function() {
|
|
140
|
+
if (this.aborted) {
|
|
141
|
+
throw this.reason;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (! (AbortSignal.timeout instanceof Function)) {
|
|
147
|
+
AbortSignal.timeout = function(ms) {
|
|
148
|
+
if (typeof ms === 'undefined') {
|
|
149
|
+
throw new TypeError('At least one 1 argument required but only 0 passed');
|
|
150
|
+
} else if (! Number.isFinite(ms)) {
|
|
151
|
+
throw new TypeError('Argument 1 is not a finite value, so it is out of range for unsigned long long.');
|
|
152
|
+
} else if (ms < 0) {
|
|
153
|
+
throw new TypeError('Argument 1 is out of range for unsigned long long.');
|
|
154
|
+
} else {
|
|
174
155
|
const controller = new AbortController();
|
|
156
|
+
setTimeout(() => controller.abort(new DOMException('The operation timed out.')), ms);
|
|
157
|
+
return controller.signal;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @see https://chromestatus.com/feature/5202879349522432
|
|
164
|
+
* @TODO How do I handle if a signal is already aborted
|
|
165
|
+
* @TODO Should controller abort on a TypeError
|
|
166
|
+
*/
|
|
167
|
+
if (! (AbortSignal.any instanceof Function)) {
|
|
168
|
+
AbortSignal.any = function(signals) {
|
|
169
|
+
if (! Array.isArray(signals)) {
|
|
170
|
+
throw new TypeError('Expected an array of signals');
|
|
171
|
+
}
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
173
|
+
const controller = new AbortController();
|
|
174
|
+
|
|
175
|
+
for (const signal of signals) {
|
|
176
|
+
if (! (signal instanceof AbortSignal)) {
|
|
177
|
+
const err = new TypeError('`signal` is not an `AbortSignal`');
|
|
178
|
+
controller.abort(err);
|
|
179
|
+
throw err;
|
|
180
|
+
} else if (signal.aborted) {
|
|
181
|
+
controller.abort(signal.reason || new DOMException('Operation aborted.'));
|
|
182
|
+
break;
|
|
183
|
+
} else {
|
|
184
|
+
signal.addEventListener('abort', ({ target }) => {
|
|
185
|
+
controller.abort(target.reason || new DOMException('Operation aborted.'));
|
|
186
|
+
}, { signal: controller.signal });
|
|
189
187
|
}
|
|
188
|
+
}
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})();
|
|
190
|
+
return controller.signal;
|
|
191
|
+
};
|
|
192
|
+
}
|