Dynamic access to Operators in both front and backend

This commit is contained in:
Felix Kaspar
2024-02-23 23:48:03 +01:00
parent 244fb36195
commit 644e0ceae9
18 changed files with 593 additions and 74 deletions

View File

@@ -0,0 +1,24 @@
import { Operator } from "../functions";
import i18next from "i18next";
function getCompileTimeOperatorList(): string[] {
return import.meta.compileTime("./listOperatorsInDir.ts");
}
export async function getOperatorByName(name: string): Promise<typeof Operator | undefined> {
// Check if exists
if(!getCompileTimeOperatorList().includes(name)) return;
i18next.loadNamespaces(name, (err, t) => { if (err) throw err; });
return (await import("../functions/" + name + ".ts"))[capitalizeFirstLetter(name)];
}
export function listOperatorNames(): string[] {
const availableOperators = getCompileTimeOperatorList();
// TODO: Implement this
return availableOperators;
}
function capitalizeFirstLetter(string: String) {
return string.charAt(0).toUpperCase() + string.slice(1);
}