
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
perfect-validator
Advanced tools
A TypeScript-based validation library that supports both static and dynamic validation with serializable models.
A TypeScript-based validation library that supports both static and dynamic validation with serializable models.
npm install perfect-validator
import { PV } from 'perfect-validator';
// Get validator instance without storage
const validator = PV.getInstance();
// Simple user profile model
const userModel = {
name: {
type: 'S',
minLength: 2,
maxLength: 50,
},
age: {
type: 'N',
min: 13,
message: 'User must be at least 13 years old',
},
email: {
type: 'EMAIL',
message: 'Invalid email format',
},
preferences: {
type: 'M',
fields: {
theme: {
type: 'S',
values: ['light', 'dark', 'system'],
default: 'system',
},
notifications: {
type: 'B',
default: true,
},
},
},
};
// Validate data
const userData = {
name: 'John Doe',
age: 25,
email: 'john@example.com',
preferences: {
theme: 'dark',
notifications: true,
},
};
const result = validator.validateStatic(userData, userModel);
console.log(result); // { isValid: true, data: userData } || { isValid: false, errors: [] }
import { PV, MongoStorage } from 'perfect-validator';
import { MongoClient } from 'mongodb';
async function setupValidator() {
// Connect to MongoDB
const client = await MongoClient.connect('mongodb://localhost:27017');
const db = client.db('your_database');
// Create storage instance
const storage = new MongoStorage(db);
// Get validator instance with storage
const validator = PV.getInstance(storage);
// Store model for later use
await validator.storeModel('userProfile', userModel);
// Later, validate data using stored model
const result = await validator.validateDynamic(userData, 'userProfile');
console.log(result); // { isValid: true, data: userData } || { isValid: false, errors: [] }
}
const orderModel = {
items: {
type: 'L',
items: {
type: 'M',
fields: {
productId: { type: 'S' },
quantity: { type: 'N', min: 1 },
},
},
},
shipping: {
type: 'M',
fields: {
method: {
type: 'S',
values: ['standard', 'express'],
},
insurance: {
type: 'B',
dependsOn: {
field: 'shipping.method',
condition: method => method === 'express',
validate: insurance => insurance === true,
message: 'Insurance is required for express shipping',
},
},
},
},
};
const passwordModel = {
password: {
type: 'S',
validate: value => {
const hasUpper = /[A-Z]/.test(value);
const hasLower = /[a-z]/.test(value);
const hasNumber = /[0-9]/.test(value);
return hasUpper && hasLower && hasNumber;
},
message: 'Password must contain uppercase, lowercase and number',
},
};
S - StringN - NumberB - BooleanL - List/ArrayM - Map/ObjectEMAIL - EmailURL - URLDATE - DatePHONE - Phone NumberREGEX - Custom Regex PatternPV was created to solve validation challenges in modern distributed applications:
// Service A: Stores the validation rules
await validator.storeModel('userProfile', userModel);
// Service B: Uses stored rules
const result = await validator.validateDynamic(userData, 'userProfile');
// Backend: Store rules in DB
await validator.storeModel('registrationRules', regModel);
// Frontend: Use same rules statically
const result = validator.validateStatic(formData, regModel);
// Update rules without deployment
const updatedRules = {
...existingRules,
age: { type: 'N', min: 16 }, // Changed age requirement
};
await validator.storeModel('userProfile', updatedRules);
Contributions are welcome! Please read our contributing guidelines before submitting a pull request.
Made with ❤️ by Zupee
FAQs
A TypeScript-based validation library that supports both static and dynamic validation with serializable models.
We found that perfect-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.