You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
681 B
JavaScript

"use strict";
const errors = require("../errors");
const getValueType = require("../util/get-value-type");
module.exports = function createFunctionValidatorFunction(options = {}) {
let guardedFunctionDescription = getValueType({
_isTypeRule: true,
_baseType: "guardedFunction",
_options: options
});
// options.args
// options.returnValue
return function validateFunction(value) {
if (typeof value === "function" && value._guardedFunction != null) {
/* FIXME: Verify that the function signature matches. */
return true;
} else {
return new errors.ValidationError(`Expected ${guardedFunctionDescription}, got ${getValueType(value)} instead`);
}
};
};