Öffentliche API zur MathCoach-IDE
jsteuer
2019-12-21 cd876c0026bf59831c0322946f0d73a8328c1b3f
src/Helpers.ts
@@ -65,13 +65,16 @@
        const traceMethod = (method: string, args?: any[]) => console.log(["[MC MOCK API]", " ", method, "(", (args ? args : [""]).join(","), ")"].join(""));
        const runtimeCheck = (errorMessage: string, isInvalid: (param: any) => boolean) => {
            return (paramName: string, value: any, optional: boolean = false) => {
                if (!optional && (value === null || value === undefined)) {
                    throw new Error(`parameter '${paramName}' is null or undefined`);
                } else {
                    if (isInvalid(value)) {
                        throw new Error(`parameter '${paramName}' is invalid: ${errorMessage}`);
                if (value === undefined) {
                    if (optional) {
                        return;
                    } else {
                        throw new Error(`missing parameter '${paramName}'`);
                    }
                }
                if (isInvalid(value)) {
                    throw new Error(`parameter '${paramName}' is invalid: ${errorMessage}`);
                }
            }
        }
        const runtimeCheckString = runtimeCheck("not a string", v => typeof v !== "string");