compat: polyfill AbortController/AbortSignal on older browsers (#2371)

This commit is contained in:
Huang Xin
2025-10-31 13:15:59 +08:00
committed by GitHub
parent 066d1c5b1e
commit 0d805a64f6
5 changed files with 41 additions and 30 deletions
+31
View File
@@ -0,0 +1,31 @@
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
// A groupBy polyfill for foliate-js
Object.groupBy ??= (iterable, callbackfn) => {
const obj = Object.create(null);
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++);
if (key in obj) {
obj[key].push(value);
} else {
obj[key] = [value];
}
}
return obj;
};
Map.groupBy ??= (iterable, callbackfn) => {
const map = new Map();
let i = 0;
for (const value of iterable) {
const key = callbackfn(value, i++),
list = map.get(key);
if (list) {
list.push(value);
} else {
map.set(key, [value]);
}
}
return map;
};