UNPKG

type-plus

Version:
30 lines 750 B
/** * Is the subject a constructor function. * * @deprecated this is not a failsafe test, * it will return true for any function that can be called with `new`. * * If the subject is an arrow function, * it can still return true after compilation. * * Thus this function is not safe to use. */ export function isConstructor(subject) { try { new subject(); } catch (err) { const msg = err?.message; if (msg && msg.indexOf('is not a constructor') >= 0) { return false; } } return true; } /** * instanceof type guard for unknown value. */ export function isInstanceof(subject, constructor) { return subject instanceof constructor; } //# sourceMappingURL=isConstructor.js.map