tch[1]; } } else { name = constructorFn.name; } return name; } /** * ### .getConstructorName(errorLike) * * Gets the constructor name for an Error instance or constructor itself. * * @name getConstructorName * @param {Error|ErrorConstructor} errorLike * @namespace Utils * @api public */ function getConstructorName(errorLike) { var constructorName = errorLike; if (errorLike instanceof Error) { constructorName = getFunctionName(errorLike.constructor); } else if (typeof errorLike === 'function') { // If `err` is not an instance of Error it is an error constructor itself or another function. // If we've got a common function we get its name, otherwise we may need to create a new instance // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more. constructorName = getFunctionName(errorLike).trim() || getFunctionName(new errorLike()); // eslint-disable-line new-cap } return constructorName; } /** * ### .getMessage(errorLike) * * Gets the error message from an error. * If `err` is a String itself, we return it. * If the error has no message, we return an empty string. * * @name getMessage * @param {Error|String} errorLike * @namespace Utils * @api public */ function getMessage(errorLike) { var msg = ''; if (errorLike && errorLike.message) { msg = errorLike.message; } else if (typeof errorLike === 'string') { msg = errorLike; } return msg; } module.exports = { compatibleInstance: compatibleInstance, compatibleConstructor: compatibleConstructor, compatibleMessage: compatibleMessage, getMessage: getMessage, getConstructorName: getConstructorName, }; },{}]},{},[1])(1) });