@mitchell-collins/validator
v1.0.2
Published
Used to validate inputs
Downloads
117
Readme
validator
Is a npm package used to validate inputs.
Install Package:
npm i @mitchell-collins/validator
The validator
is used to validate inputs.
The validator
is a module that has multiply methods that check a condition and if input doesn't match
condition then a error is thrown with a message outlining cause of error.
The validator
has multiply methods these include:
checkUndefined
- checks if a variable is undefinedcheckUndefinedArray
- checks each variable in array if they are undefinedcheckDataType
- checks if a variable has the requested datatypecheckDataTypeArray
- checks each variable in an array if they have the requested datatypecheckInstanceType
- checks in an instance is the requested instancetypecheckInstanceTypeArray
- checks each instance in an array if are the requested instancetypecheckSuperClass
- checks if a instance is a child of the requested super classcheckSuperClassArray
- checks each instance in a array if they are the child of the requested super class
The checkSuperClass
and checkSuperClassArray
methods require that you create a attribute that holds the name of the super class which has a getter method: getSuper
.
You can use superclass
which defines a super attribute that holds the name of the super class along with getter and setter methods. Which can be accessed here:
- https://github.com/MitchellCollins/SuperClass
- https://www.npmjs.com/package/@mitchell-collins/superclass
Examples:
function squareNumber(number) {
validator.checkUndefined(number);
validator.checkDataType(number, "number");
return number * number;
}
function addNumbers(num1, num2) {
validator.checkUndefinedArray([num1, num2]);
validator.checkDataTypeArray([num1, num2], "number");
return num1 + num2;
}