UNPKG

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