* Take the parameters given to the AutoNumeric object, and output the three variables that are needed to finish initializing it : * - domElement : The target DOM element * - initialValue : The initial value, or `null` if none is given * - userOptions : The option object * *
(arg1, arg2, arg3)
| 952 | * @private |
| 953 | */ |
| 954 | static _setArgumentsValues(arg1, arg2, arg3) { |
| 955 | // Basic check on the argument count |
| 956 | if (AutoNumericHelper.isNull(arg1)) { |
| 957 | AutoNumericHelper.throwError('At least one valid parameter is needed in order to initialize an AutoNumeric object'); |
| 958 | } |
| 959 | |
| 960 | // Prepare the arguments in order to create the AutoNumeric object with the right values |
| 961 | // Test the argument types |
| 962 | const isArg1Element = AutoNumericHelper.isElement(arg1); |
| 963 | const isArg1String = AutoNumericHelper.isString(arg1); |
| 964 | |
| 965 | const isArg2Object = AutoNumericHelper.isObject(arg2); |
| 966 | const isArg2Array = Array.isArray(arg2) && arg2.length > 0; |
| 967 | const isArg2Number = AutoNumericHelper.isNumberOrArabic(arg2) || arg2 === ''; |
| 968 | const isArg2PreDefinedOptionName = this._isPreDefinedOptionValid(arg2); |
| 969 | const isArg2Null = AutoNumericHelper.isNull(arg2); |
| 970 | const isArg2EmptyString = AutoNumericHelper.isEmptyString(arg2); |
| 971 | |
| 972 | const isArg3Object = AutoNumericHelper.isObject(arg3); |
| 973 | const isArg3Array = Array.isArray(arg3) && arg3.length > 0; |
| 974 | const isArg3Null = AutoNumericHelper.isNull(arg3); |
| 975 | const isArg3PreDefinedOptionName = this._isPreDefinedOptionValid(arg3); |
| 976 | |
| 977 | // Given the parameters passed, sort the data and return a stable state before the initialization |
| 978 | let domElement; |
| 979 | let userOptions; |
| 980 | let initialValue; |
| 981 | |
| 982 | //TODO Simplify those tests --> |
| 983 | if (isArg1Element && isArg2Null && isArg3Null) { |
| 984 | // new AutoNumeric(domElement); // With the default options |
| 985 | domElement = arg1; |
| 986 | initialValue = null; |
| 987 | userOptions = null; |
| 988 | } else if (isArg1Element && isArg2Number && isArg3Null) { |
| 989 | // new AutoNumeric(domElement, 12345.789); // With the default options, and an initial value |
| 990 | // new AutoNumeric(domElement, '12345.789'); |
| 991 | domElement = arg1; |
| 992 | initialValue = arg2; |
| 993 | userOptions = null; |
| 994 | } else if (isArg1Element && isArg2Object && isArg3Null) { |
| 995 | // new AutoNumeric(domElement, { options }); // With one option object |
| 996 | domElement = arg1; |
| 997 | initialValue = null; |
| 998 | userOptions = arg2; |
| 999 | } else if (isArg1Element && isArg2PreDefinedOptionName && isArg3Null) { |
| 1000 | // new AutoNumeric(domElement, 'euroPos'); // With one pre-defined option name |
| 1001 | domElement = arg1; |
| 1002 | initialValue = null; |
| 1003 | userOptions = this._getOptionObject(arg2); |
| 1004 | } else if (isArg1Element && isArg2Array && isArg3Null) { |
| 1005 | // new AutoNumeric(domElement, [{ options1 }, { options2 }]); // With multiple option objects (the latest option overwriting the previous ones) |
| 1006 | domElement = arg1; |
| 1007 | initialValue = null; |
| 1008 | userOptions = this.mergeOptions(arg2); |
| 1009 | } else if (isArg1Element && (isArg2Null || isArg2EmptyString) && isArg3Object) { |
| 1010 | // new AutoNumeric(domElement, null, { options }); // With one option object |
| 1011 | domElement = arg1; |
no test coverage detected