Package Exports
- ajt-validator
- ajt-validator/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ajt-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ajt-validator
A comprehensive, flexible validation library for JavaScript and TypeScript applications that provides robust data validation with minimal configuration.
Features
- Type-safe validation - Built with TypeScript for strong typing
- Modular architecture - Use only the validators you need
- Extensible framework - Create custom validators by extending base classes
- Rich validation results - Detailed error information and metadata
- Zero dependencies - Lightweight and efficient
- Framework agnostic - Works with any JS/TS project
Core Validators
Personal Information
DOBValidator- Date of birth validation with age calculationsNameValidator- Name validation with customizable format rulesEmailValidator- Email address validationPhoneValidator- Phone number validation with international format supportAuthentication
PasswordValidator- Password strength and format validationUsernameValidator- Username format validationGeneral Purpose
StringValidator- Text validation with length and format optionsNumberValidator- Numeric validation with range checkingDateValidator- Date format and range validation
Installation
npm install ajt-validator
Usage
import { PersonalValidator } from 'ajt-validator';
// Create a validator instance
const nameValidator = new PersonalValidator.NameValidator({
minLength: 2,
maxLength: 50,
allowSpecialChars: true
});
// Validate input
const result = nameValidator.validate("O'Connor");
console.log(result.isValid); // true
Validation Results
All validators return consistent result objects with:
- isValid - Boolean indicating validation success
- value - The validated (and possibly transformed) value
- errors - Array of detailed error objects with code and message
- Additional metadata specific to each validator type
Extending the Library
Create custom validators by extending the base classes:
import { BaseValidator } from 'ajt-validator';
class CustomValidator extends BaseValidator {
validate(value) {
// Custom validation logic
}
}
License
MIT