UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * Create a syntax error with the message:
3 * 'Wrong number of arguments in function <fn> (<count> provided, <min>-<max> expected)'
4 * @param {string} fn Function name
5 * @param {number} count Actual argument count
6 * @param {number} min Minimum required argument count
7 * @param {number} [max] Maximum required argument count
8 * @extends Error
9 */
10export function ArgumentsError(fn, count, min, max) {
11 if (!(this instanceof ArgumentsError)) {
12 throw new SyntaxError('Constructor must be called with the new operator');
13 }
14
15 this.fn = fn;
16 this.count = count;
17 this.min = min;
18 this.max = max;
19 this.message = 'Wrong number of arguments in function ' + fn + ' (' + count + ' provided, ' + min + (max !== undefined && max !== null ? '-' + max : '') + ' expected)';
20 this.stack = new Error().stack;
21}
22ArgumentsError.prototype = new Error();
23ArgumentsError.prototype.constructor = Error;
24ArgumentsError.prototype.name = 'ArgumentsError';
25ArgumentsError.prototype.isArgumentsError = true;
\No newline at end of file