Simple and Effective Object Validator
npm install satpam

npm install satpam --save
`
Quick Usage
`js
const satpam = require('satpam');const rules = {
name: ['required'],
phone: ['required', 'numeric'],
email: ['required', 'email']
office: {
secondaryEmail: ['email'],
}
};
const input = {
name: 'Sendy',
title: 'Lord',
phone: 'hi there123',
email: 'test@example.com',
office: {
secondaryEmail: 'invalid email',
}
};
const result = satpam.validate(rules, input);
if (result.success === true) {
// valid
} else {
// invalid
result.messages.office.secondaryEmail.email === 'Secondary Email must be email.';
result.messages.phone.number === 'Phone must be numeric.';
}
`
Isolated Satpam Instance
Satpam create method will return an isolated Satpam instance based on current state of satpam validation rules and messages. The instance won't be affected when you setting up a custom validation rules or messages.- Each instance will have cloned validation rules and messages, so it's safe to add or override validation rule without affecting other validator instances or the global satpam validator.
- The cloned validation rules and messages will be based on the current state of the global satpam validator. See Custom Rules
`js
const satpam = require('satpam');const validatorOne = satpam.create();
const validatorTwo = satpam.create();
`Front End Usage
For front end usage, you can use the dedicated front end lib.
`js
import satpam from 'satpam/lib/frontend';
`
Additionally, it's better to create your own validator instance with only the needed rules.
This will help reduce build size especially if your front end application is intended for end users.
`js
import Validator from 'satpam/lib/frontend/validator';
import minLength from 'satpam/lib/validators/min-length';
import maxLength from 'satpam/lib/validators/max-length';const customValidator = new Validator({
validators: [minLength, maxLength]
});
const result = customValidator.validate(
{ token: ['minLength:11', 'maxLength:16'] },
{ token: '12345' }
);
`Available Rules
- required
- numeric
- integer
- email
- notDisposableEmail (well suited with email validation)
- image
- alpha
- alphanumeric
- boolean
- creditCard
- containsAlphabet
- containsDigit
- containsLowerCase
- containsUpperCase
- date
- dateFormat:
- dateAfter:
- dateBefore:
- dateTimeAfter:
- dateTimeAfterOrEqual:
- dateTimeBefore:
- dateTimeBeforeOrEqual:
- timeAfter: