avoid Object.fromEntries() and some instances of globalThis

Not supported on early iOS 12. This can be reverted after iOS 12
support is dropped, which should be soon.
This commit is contained in:
Damien Elmes 2021-11-02 12:54:06 +10:00
parent dd4c4eb07c
commit 37df65d0c8
3 changed files with 14 additions and 5 deletions

View file

@ -23,12 +23,17 @@ function toFluentNumber(num: number): FluentNumber {
function formatArgs(
args: Record<string, FluentVariable>,
): Record<string, FluentVariable> {
return Object.fromEntries(
Object.entries(args).map(([key, value]) => [
const entries: [string, FluentVariable][] = Object.entries(args).map(
([key, value]) => [
key,
typeof value === "number" ? toFluentNumber(value) : value,
]),
],
);
const out: Record<string, FluentVariable> = {};
for (const [key, value] of entries) {
out[key] = value;
}
return out;
}
export function getMessage(

View file

@ -10,7 +10,7 @@
export const runtimeLibraries = {};
// Export require() as a global.
(globalThis as any).require = function (name: string): unknown {
(window as any).require = function (name: string): unknown {
const lib = runtimeLibraries[name];
if (lib === undefined) {
throw new Error(`Cannot require(${name}) at runtime.`);

View file

@ -1,9 +1,13 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/* eslint
@typescript-eslint/no-explicit-any: "off",
*/
// A standalone bundle that adds mutateNextCardStates to the anki namespace.
// When all clients are using reviewer.js directly, we can get rid of this.
import { mutateNextCardStates } from "./answering";
globalThis.anki.mutateNextCardStates = mutateNextCardStates;
(window as any).anki.mutateNextCardStates = mutateNextCardStates;