Type Safe
Written in TypeScript with full type definitions and support for built-in and custom types
Lightweight and flexible runtime data validation for Node.js applications
import Schema from 'validno';
// Define your schema
const userSchema = new Schema({
name: {
type: String,
required: true,
rules: {
lengthMin: 2,
lengthMax: 50
}
},
email: {
type: String,
required: true,
rules: {
isEmail: true
}
},
age: {
type: Number,
required: false,
rules: {
min: 18,
max: 120
}
}
});
// Validate data
const userData = {
name: "Barney Stinson",
email: "barney@himym.com",
age: 35
};
const result = userSchema.validate(userData);
if (result.ok) {
console.log('Validation passed!');
} else {
console.log('Errors:', result.errors);
}
npm i validno