New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cached-validations

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cached-validations

Easy and fast validations with cached results

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

cached-validations

Create validation functions that cache results

Install

$ npm install --save cached-validations

Usage

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'}

API

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.

License

MIT © Brandon Dail

Keywords

FAQs

Package last updated on 23 Apr 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc