UNPKG

type-plus

Version:
35 lines 944 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isInstanceof = exports.isConstructor = void 0; /** * 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. */ 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; } exports.isConstructor = isConstructor; /** * instanceof type guard for unknown value. */ function isInstanceof(subject, constructor) { return subject instanceof constructor; } exports.isInstanceof = isInstanceof; //# sourceMappingURL=isConstructor.js.map