
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
cached-validations
Advanced tools
Create validation functions that cache results
$ npm install --save cached-validations
Create a validation schema and then you can create a validation function that takes in values and outputs any errors based on the passed validation functions.
If an error has already been returned for a specific value then it will be cached and returned on the next invocation, making this a relatively performant option for doing things like form validations on keyup
.
import createValidator from 'cached-validations';
const formValidations = {
email: email => {
if (!email) return 'Email is required';
if (isNotEmail(email)) return 'Must be a valid email';
},
age: age => {
if (!age) return 'Age is required';
if (age > 120 || age < 13) return 'Must provide a valid age.'
}
}
const formValidator = createValidator(formValidations);
const dummyInput = {
email: 'notanemail',
age: 44
}
const errors = formValidator(dummyInput)
// {email: 'Must be a valid email'}
createValidator(validations: object) => function => object
Takes an object mapping validation functions to keys, returns a function that will validate objects with those same keys and return any errors based on the initially provided validations.
MIT © Brandon Dail
FAQs
Easy and fast validations with cached results
We found that cached-validations 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.