UNPKG

1.02 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
20 this.message = 'Wrong number of arguments in function ' + fn +
21 ' (' + count + ' provided, ' +
22 min + ((max !== undefined && max !== null) ? ('-' + max) : '') + ' expected)'
23
24 this.stack = (new Error()).stack
25}
26
27ArgumentsError.prototype = new Error()
28ArgumentsError.prototype.constructor = Error
29ArgumentsError.prototype.name = 'ArgumentsError'
30ArgumentsError.prototype.isArgumentsError = true