1.0.14 • Published 4 years ago

govocal_validator v1.0.14

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

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

  1. validateParameters(key, value, entityType) : This method can be used to validate the parameters based on the key entity type the user has selected.

  2. validateFact(fact) : This method can be used to validate if a string passed is empty or not.

  3. validateOperator(operator) : This method is similar to the above function. It was created to assist the validateFact method.

  4. 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." 
}
1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago