UNPKG

is-what

Version:

JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.

21 lines (20 loc) 583 B
import { getType } from './getType.js'; import { isType } from './isType.js'; export function isInstanceOf(value, classOrClassName) { if (typeof classOrClassName === 'function') { for (let p = value; p; p = Object.getPrototypeOf(p)) { if (isType(p, classOrClassName)) { return true; } } return false; } else { for (let p = value; p; p = Object.getPrototypeOf(p)) { if (getType(p) === classOrClassName) { return true; } } return false; } }