Gathering detailed insights and metrics for validata-jsts
Gathering detailed insights and metrics for validata-jsts
Gathering detailed insights and metrics for validata-jsts
Gathering detailed insights and metrics for validata-jsts
A simple, flexible, and extensible JavaScript/TypeScript data validation library, Allows dynamically Validation with schemas
npm install validata-jsts
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
24 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Jun 13, 2025
Latest Version
1.2.12
Package Id
validata-jsts@1.2.12
Unpacked Size
60.27 kB
Size
11.85 kB
File Count
7
NPM Version
11.1.0
Node Version
23.6.0
Published on
Apr 16, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
6
Validata-JSTS is a lightweight rule-based validation library for JavaScript/TypeScript. You can define flexible and powerful validation rules using strings or schema objects, including support for custom rules, nested fields, ObjectIds, arrays, and more.
validateWithSchema
extractRulesFromSchema
string
, number
, boolean
, email
, pwd
, array
, date
, objectid
extend
1npm install validata-jsts
1import { isInValiData } from "validata-jsts"; 2 3const rules = [ 4 "name-string-min3-max20", 5 "email-email", 6 "age-number-min18-max99", 7 "password-pwd-min8", 8 "bio-string-optional" 9]; 10 11const data = { 12 name: "Abraham", 13 email: "abraham@example.com", 14 age: 25, 15 password: "StrongPass123!" 16}; 17 18const result = isInValiData(rules, data); 19 20if (result) { 21 console.log("❌ Validation errors:", result); 22} else { 23 console.log("✅ Passed validation"); 24}
1const rule = { 2 name: "string-min3-max30", 3 email: "email", 4 age: "number-min18", 5 password: "pwd-min8", 6 bio: "string-optional" 7}; 8 9const data = { 10 name: "Abraham", 11 email: "abraham@example.com", 12 age: 25, 13 password: "StrongPass123!" 14}; 15 16const result = isInValiData(rules, data); 17 18if (result) { 19 console.log("❌ Validation errors:", result); 20} else { 21 console.log("✅ Passed validation"); 22}
fieldName-type-rule1-rule2-err:Custom error
Type | Description |
---|---|
string | Text fields |
number | Numeric fields |
boolean | True/false values |
Valid email address | |
pwd | Strong password (custom rules) |
date | Date string in YYYY-MM-DD |
objectid | Valid MongoDB ObjectId |
array | Generic array support |
Use optional
to allow a field to be skipped:
1"bio-string-optional"
Use err:
or valerr:
to specify your own messages:
1"email-email-err:Invalid email address" 2"password-pwd-min8-valerr:Password too weak"
validateWithSchema(schemaObject, data)
1import { validateWithSchema } from "validata-jsts"; 2import { Schema, validateWithSchema } from "validata-jsts"; 3 4const schema = new Schema({ 5 name: { type: "string", min: 3, max: 30 }, 6 email: { type: "email" }, 7 age: { type: "number", min: 18 }, 8 password: { type: "pwd", min: 8 }, 9 bio: { type: "string"} 10}); 11 12 13const data = { 14 name: "John", 15 email: "john@example.com", 16 age: 22, 17 password: "StrongPass1!" 18}; 19 20const result = validateWithSchema(schema, data); 21console.log(result) 22 23//Output 24false
extractRulesFromSchema(mongooseSchema)
1import mongoose from "mongoose"; 2import { extractRulesFromSchema } from "validata-jsts"; 3 4const schema = new mongoose.Schema({ 5 name: { type: String, required: true }, 6 email: { type: String }, 7 password: { type: String, required: true }, 8 profile: { 9 age: { type: Number, min: 16, required: true }, 10 bio: { type: String, maxlength: 400 } 11 }, 12 userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, 13}); 14 15const rules = extractRulesFromSchema(schema); 16 17// Output: 18[ 19 "name-string-req", 20 "email-email", 21 "password-pwd-req", 22 "profile.age-number-req-min16", 23 "profile.bio-string-max400", 24 "userId-objectid-req" 25]
extend
1import { extend, isInValiData } from "validata-jsts"; 2 3extend("startsWith", (value, expected) => { 4 if (typeof value !== "string") return "Must be a string"; 5 if (!value.startsWith(expected)) return `Must start with ${expected}`; 6 return null; 7}); 8 9const rules = ["username-string-startsWith:dev"]; 10const data = { username: "devAbraham" }; 11 12const result = isInValiData(rules, data);
1extend("naPhone", (value) => { 2 if (!/^(\+234|0)[789][01]\d{8}$/.test(value)) { 3 return "Invalid Nigerian phone number"; 4 } 5 return null; 6}); 7 8const rules = ["phone-naPhone-err:Provide a valid Nigerian number"];
1// type can be imported : ValidatorFn incase 2 3import { extend, ValidatorFn } from "validata-jsts"; 4 5// default config from user 6const minLengthCheck: ValidatorFn = (value, _, config = { min: 5 }) => { 7 if (value.length < config.min) { 8 return `{Value} is less than the minimum length of ${config.min}`; 9 } 10 return null; 11}; 12 13extend("equal", (value, cond, config) => minLengthCheck(value, cond, { min: 10 })); 14 15const rules = ["phone-equal"]; 16const value ={ idNumber :"abmercy"}; 17const result = isInValidata(rules, value) 18console.log(result); 19 // Output: "phone: value is less than the minimum length of 5
You can go as far as attaching your equating value to the name and then extract it... from the condition props
1// if its a number and your fucntion name length equal is of length 4 your substring value will be 4
2const condValue = Number.parseInt(conditions[0].substring(4)) // if condition is one or you map it
1// then you can validata your value against the condition, you should have your extend function like this 2const minLengthCheck: ValidatorFn = (value, conditions, config = { min: 5 }) =>{ 3 // your validation here logic here 4}
Then pass it into your rule and we will take care of that 🌝
1const rule = ["name-equalAbraham"] 2// we will take it from there.
string
1"name-string-min3-max50" 2"key-string-16" //must be exactly 8 character long
number
1"age-number-min18-max60" 2"packs-number-8" //must be exactly equal to 8
boolean
1"isAdmin-boolean"
email
1"email-email"
pwd
1"password-pwd-min8"
Password must include:
date
1"birthdate-date-min1990_01_01-max2020_12_31"
objectid
1"userId-objectid"
array
1"tags-array"
array<{ name: string }>
- coming soonif:field=value
) - coming soon!
prefix (for rule strings) - coming soon1const rule = { 2 name: "string-min3-max30", 3 email: "email", 4 password: "pwd-min8", 5 confirmPassword: "string-equal:Password123!", 6 acceptTerms: "boolean" 7}; 8 9const input = { 10 name: "Jane Doe", 11 email: "jane@example.com", 12 password: "Password123!", 13 confirmPassword: "Password123!", 14 acceptTerms: true 15}; 16 17const result = isInValiData(rule, input);
1const rule = [ 2 "name-string-min3-max30", 3 "email-email", 4 "password-pwd-max18", 5 "confirmPassword-pwd-max18", 6 "acceptTerms-boolean" 7 ]; 8 9const input = { 10 name: "Jane Doe", 11 email: "jane@example.com", 12 password: "Password123!", 13 confirmPassword: "Password123!", 14 acceptTerms: true 15}; 16 17const result = isInValiData(rule, input);
git checkout -b feature-name
This project is licensed under the MIT License
Coming soon: conditional rules, nested object arrays, and media validation support.
.
No vulnerabilities found.
No security vulnerabilities found.