Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Magical, Flexible and Extendible Javascript Validation.
npm:
npm i validazz
Yarn:
yarn add validazz
import Validator, { rules } from 'validazz'
const mySuperCoolValidator = Validator.factory()
// Let's add some rules
mySuperCoolValidator.addRule(rules.isRequired)
mySuperCoolValidator.addRules([rules.minLength(2), rules.maxLength(8)])
mySuperCoolValidator.addRule(rules.isString)
// How about a custom rule?
const customRule = {
runWithValue: value => {
if (value !== '🤪') return false
return true
},
message: 'Houston, we got a problem',
}
mySuperCoolValidator.addRule(customRule)
// Okay let's start validating
const { success, failed } = mySuperCoolValidator.runWithValue('hello')
if (success) {
console.log('Wow, this was validated just like that')
} else {
const { message } = failed
console.log(`Okay so here's the error message: ${failed}`)
}
For a list of all the included rules, be sure to check the RULES.md file
Validation Factory, where all the validation magic happens
Type: Validator
rules
Array<ValidationRule> List of rules to initalize with (optional, default []
)Add a rule to the factory
rule
ValidationRule A validation ruleReturns Validator Validator instance
Add a rules to the factory
rules
Array<ValidationRule> An array of rules to addReturns Validator Validator instance
Run the factory and validate!
value
string The string to be validatedReturns ValidatorResult The validation outcome
Meta
validate(value: string)
instead. Depricated since v1.1Validates a string
value
String The string to be validatedconst { success, failed } = Validator.factory(rules.isRequired).validate('hello')
Returns ValidatorResult The validation outcome
Create a new validation factory
rules
Array<ValidationRule> List of rules to initalize the factory with (optional, default []
)const validator = Validator.factory([])
Returns Validator Validator instance
The validation function for this rule. It takes the a string/integer value and returns a boolean.
Type: Function
value
string Value of array elementconst rule = {
runWithValue(value) {
return value != null
}
}
Returns Boolean If it returns true, the field is valid.
A validation rule
Type: Object
message
string A custom error message for this validation rulerunWithValue
runWithValue Validation callback// Basic Example
const validationRule = {
message: 'This field is required',
runWithValue(value) {
return value != null
}
}
// Example with parameters
const minimum = (min) => ({
message: `Amount must be greater than ${min}`,
runWithValue(value) {
const value = Number(value)
return value > min
}
})
The validation result
Type: Object
success
Boolean The outcome of the validationfailed
ValidationRule An optional value. Returns the rule that failed to validateconst { success, failed } = Validator.factory(rules.isRequired).validate('hello')
if (success) {
alert('validated')
} else {
const { message } = failed
alert(`Failed: ${message}`)
}
MIT © Jesse Onolememen
FAQs
Magical, Flexible and Extendible Javascript Validation
The npm package validazz receives a total of 0 weekly downloads. As such, validazz popularity was classified as not popular.
We found that validazz demonstrated a not healthy version release cadence and project activity because the last version was released 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.