mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.
36 lines (30 loc) • 1.03 kB
JavaScript
/**
* Create a TypeError with message:
* 'Function <fn> does not support a parameter of type <type>';
* @param {String} fn Function name
* @param {*...} [types] The types of the function arguments
* @extends TypeError
*/
function UnsupportedTypeError(fn, types) {
if (!(this instanceof UnsupportedTypeError)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
this.fn = fn;
this.types = Array.prototype.splice.call(arguments, 1);
if (!fn) {
this.message = 'Unsupported type of argument';
}
else {
if (this.types.length == 0) {
this.message = 'Unsupported type of argument in function ' + fn;
}
else {
this.message = 'Function ' + fn + '(' + this.types.join(', ') + ') not supported';
}
}
this.stack = (new Error()).stack;
}
UnsupportedTypeError.prototype = new TypeError();
UnsupportedTypeError.prototype.constructor = TypeError;
UnsupportedTypeError.prototype.name = 'UnsupportedTypeError';
module.exports = UnsupportedTypeError;