UNPKG

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