@shgysk8zer0/polyfills 0.3.11 → 0.3.12
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 +8 -0
- package/all.js +1 -0
- package/all.min.js +11 -11
- package/all.min.js.map +1 -1
- package/package.json +3 -2
- package/promise.js +21 -0
- package/string.js +5 -0
- package/symbols.js +16 -0
- package/url.js +10 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgysk8zer0/polyfills",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A collection of JavaScript polyfills",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@aegisjsproject/sanitizer": "^0.1.0",
|
|
81
|
-
"@aegisjsproject/trusted-types": "^1.0.1"
|
|
81
|
+
"@aegisjsproject/trusted-types": "^1.0.1",
|
|
82
|
+
"string-dedent": "^3.0.1"
|
|
82
83
|
}
|
|
83
84
|
}
|
package/promise.js
CHANGED
|
@@ -67,4 +67,25 @@ if ('Promise' in globalThis) {
|
|
|
67
67
|
return def;
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
if (! (Promise.fromEntries instanceof Function)) {
|
|
72
|
+
Promise.fromEntries = async function fromEntries(entries) {
|
|
73
|
+
const keys = [];
|
|
74
|
+
const values = [];
|
|
75
|
+
|
|
76
|
+
for (const [key, value] of entries) {
|
|
77
|
+
keys.push(key);
|
|
78
|
+
values.push(value);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return await Promise.all(values)
|
|
82
|
+
.then(values => Object.fromEntries(values.map((value, i) => [keys[i], value])));
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!(Promise.ownProperties instanceof Function)) {
|
|
87
|
+
Promise.ownProperties = async function ownProperties(obj) {
|
|
88
|
+
return await Promise.fromEntries(Object.entries(obj));
|
|
89
|
+
};
|
|
90
|
+
}
|
|
70
91
|
}
|
package/string.js
ADDED
package/symbols.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { polyfillMethod } from './utils.js';
|
|
2
|
+
|
|
1
3
|
if ('Symbol' in globalThis) {
|
|
4
|
+
const known = new Set(
|
|
5
|
+
Reflect.ownKeys(Symbol)
|
|
6
|
+
.filter(item => typeof Symbol[item] === 'symbol')
|
|
7
|
+
.map(key => Symbol[key])
|
|
8
|
+
);
|
|
9
|
+
|
|
2
10
|
if (typeof Symbol.toStringTag === 'undefined') {
|
|
3
11
|
Symbol.toStringTag = Symbol('Symbol.toStringTag');
|
|
4
12
|
}
|
|
@@ -6,4 +14,12 @@ if ('Symbol' in globalThis) {
|
|
|
6
14
|
if (typeof Symbol.iterator === 'undefined') {
|
|
7
15
|
Symbol.iterator = Symbol('Symbol.iterator');
|
|
8
16
|
}
|
|
17
|
+
|
|
18
|
+
polyfillMethod(Symbol, 'isRegistered', function(symbol) {
|
|
19
|
+
return typeof symbol === 'symbol' && typeof Symbol.keyFor(symbol) === 'string';
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
polyfillMethod(Symbol, 'isWellKnown', function(symbol) {
|
|
23
|
+
return known.has(symbol);
|
|
24
|
+
});
|
|
9
25
|
}
|
package/url.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { polyfillMethod } from './utils.js';
|
|
2
2
|
|
|
3
|
-
polyfillMethod(URL, '
|
|
3
|
+
polyfillMethod(URL, 'parse', (url, base) => {
|
|
4
4
|
try {
|
|
5
|
-
new URL(
|
|
6
|
-
|
|
5
|
+
return new URL(url, base);
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
polyfillMethod(URL, 'canParse', (url, base) => {
|
|
12
|
+
try {
|
|
13
|
+
return new URL(url, base) instanceof URL;
|
|
7
14
|
} catch {
|
|
8
15
|
return false;
|
|
9
16
|
}
|