name:
dist/Utilities/ArgsChecker.js
-rw-r--r--
2335
1"use strict";
2exports.__esModule = true;
3var Errors_1 = require("../Errors");
4/**
5 * Static class to check argument length within expected ranges when calling functions.
6 */
7var ArgsChecker = /** @class */ (function () {
8 function ArgsChecker() {
9 }
10 /**
11 * Checks to see if the arguments are of the correct length.
12 * @param args to check length of
13 * @param length expected length
14 * @param caller name of the function calling this function, for use in error message formatting
15 */
16 ArgsChecker.checkLength = function (args, length, caller) {
17 if (args.length !== length) {
18 var functionName = caller !== undefined ? " to " + caller : "";
19 throw new Errors_1.NAError("Wrong number of arguments" + functionName + ". Expected " + length
20 + " arguments, but got " + args.length + " arguments.");
21 }
22 };
23 /**
24 * Checks to see if the arguments are at least a certain length.
25 * @param args to check length of
26 * @param length expected length
27 * @param caller name of the function calling this function, for use in error message formatting
28 */
29 ArgsChecker.checkAtLeastLength = function (args, length, caller) {
30 if (args.length < length) {
31 var functionName = caller !== undefined ? " to " + caller : "";
32 throw new Errors_1.NAError("Wrong number of arguments" + functionName + ". Expected " + length
33 + " arguments, but got " + args.length + " arguments.");
34 }
35 };
36 /**
37 * Checks to see if the arguments are within a max and min, inclusively
38 * @param args to check length of
39 * @param low least number of arguments
40 * @param high max number of arguments
41 * @param caller name of the function calling this function, for use in error message formatting
42 */
43 ArgsChecker.checkLengthWithin = function (args, low, high, caller) {
44 if (args.length > high || args.length < low) {
45 var functionName = caller !== undefined ? " to " + caller : "";
46 throw new Errors_1.NAError("Wrong number of arguments" + functionName + ". Expected between " + low
47 + " and " + high + " arguments, but got " + args.length + " arguments.");
48 }
49 };
50 return ArgsChecker;
51}());
52exports.ArgsChecker = ArgsChecker;