govocal_validator v1.0.14
Input Validator
This is a simple input validator that validates the data based on the entity type and value.
This has different methods defined to solve different problems. This package is built using the @hapi/joi input validator.
I have defined the following schemas to validate different input and parameters:
phoneSchema: This is the schema to validate a valid phone number.
emailSchema: This is the schema to validate a valid email ID.
dateSchema: This is the schema to validate a valid date in the format 'YYYY/MM/DD'.
urlSchema: This is the schema to validate a valid URL.
currencySchema: This is the schema to validate a valid currency and price.
numberSchema: This is the schema to validate a valid number.
Methods
validateParameters(key, value, entityType) : This method can be used to validate the parameters based on the key entity type the user has selected.
validateFact(fact) : This method can be used to validate if a string passed is empty or not.
validateOperator(operator) : This method is similar to the above function. It was created to assist the validateFact method.
validateValue(fact, operator, value, entity) : This method using all the above methods to verify and validate the input from all aspects.
Examples
const validator = require('govocal_validator');
// Phone parameter
const phoneNumber = {
key: 'phone'
value: '+919876543210'
entityType: 'phoneNumber'
}
// Email parameter
const email = {
key: 'email',
value: 'gmail.com',
entityType: 'emailID'
}
// Number parameter
const number = {
key: 'number',
value: 786,
entityType: 'number'
}
const inputArray = [] // The array that will be sent as a input
const outputArray = [] // The array to store or recieve and store the errors
// Add all parameters to the input array
inputArray.push(phoneNumber)
inputArray.push(email)
inputArray.push(number)
inputArray.forEach(input => {
outputArray.push(validator.validateParameters(input.key, input.value, input.entityType))
})
Your output will be available in the format:
{
"value": "This will be the value you sent to verify",
"error": "If there is an error in the value, only then this message will be sent."
}