UNPKG

1.06 kBJavaScriptView Raw
1'use strict'
2
3/**
4 * Create a syntax error with the message:
5 * 'Wrong number of arguments in function <fn> (<count> provided, <min>-<max> expected)'
6 * @param {string} fn Function name
7 * @param {number} count Actual argument count
8 * @param {number} min Minimum required argument count
9 * @param {number} [max] Maximum required argument count
10 * @extends Error
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
22 this.message = 'Wrong number of arguments in function ' + fn +
23 ' (' + count + ' provided, ' +
24 min + ((max !== undefined && max !== null) ? ('-' + max) : '') + ' expected)'
25
26 this.stack = (new Error()).stack
27}
28
29ArgumentsError.prototype = new Error()
30ArgumentsError.prototype.constructor = Error
31ArgumentsError.prototype.name = 'ArgumentsError'
32ArgumentsError.prototype.isArgumentsError = true
33
34module.exports = ArgumentsError