drab
Version:
Interactivity for You
12 lines (11 loc) • 369 B
JavaScript
/**
* @param actual Element to validate.
* @param expected Constructor of the expected element.
* @returns If valid returns `actual` otherwise throws `TypeError`.
*/
export const validate = (actual, expected) => {
if (!(actual instanceof expected)) {
throw new TypeError(`${actual} is not an instance of ${expected.name}.`);
}
return actual;
};