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.

18 lines
472 B
JavaScript

"use strict";
// FIXME: Package as @validatem/is-instance-of
const ValidationError = require("@validatem/error");
module.exports = function isInstanceOf(constructor) {
if (typeof constructor !== "function") {
throw new Error(`The constructor or class to validate against, must be a function`);
}
return function isInstanceOf(value) {
if (!(value instanceof constructor)) {
throw new ValidationError(`Must be an instance of ${constructor.name}`);
}
};
};