UNPKG

963 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = assertDependencies;
7
8/**
9 * Assert that all dependencies of a list with dependencies are available in the provided object `math`.
10 *
11 * Will throw an exception when there are dependencies missing.
12 *
13 * @param {Object} math
14 * @param {string[]} dependencies
15 * @param {string} name Name for the function to be created. Used to generate a useful error message
16 */
17function assertDependencies(math, dependencies, name) {
18 if (!dependencies.every(function (dependency) {
19 return dependency in math;
20 })) {
21 var missingDependencies = dependencies.filter(function (dependency) {
22 return !(dependency in math);
23 }); // TODO: create a custom error class for this, a MathjsError or something like that
24
25 throw new Error("Cannot create function ".concat(name, ", ") + "some dependencies are missing: ".concat(missingDependencies.join(', '), "."));
26 }
27}
\No newline at end of file