browsertrix/frontend/src/utils/polyfills.ts
Emma Segal-Grossman d1156b0145
enable a few more useful eslint suggestions & correct some more types (#1517)
## Changes

Implements suggestions from
https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/
and
https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful,
along with a couple more auto-fixable consistency rules.

Of note:
- Functions that return a promise are marked as async
- Suggestions now appear for where to simplify boolean checks,
non-nullish assertions, and optional chaining
2024-02-09 16:14:08 -08:00

25 lines
636 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unnecessary-condition */
// cSpell:disable
/**
* Object.entriesFrom() polyfill
* @author Chris Ferdinandi
* @license MIT
*/
if (!Object.fromEntries) {
Object.fromEntries = function <T = any>(
entries: Iterable<readonly [PropertyKey, T]>,
): { [k: string]: T } {
if (!entries?.[Symbol.iterator]) {
throw new Error(
"Object.fromEntries() requires a single iterable argument",
);
}
const obj: { [k: PropertyKey]: T } = {};
for (const [key, value] of entries) {
obj[key] = value;
}
return obj;
};
}