🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

async-validator

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-validator

validate form asynchronous

4.2.5
latest
Version published
Weekly downloads
1.3M
2.46%
Maintainers
2
Weekly downloads
 
Created

What is async-validator?

The async-validator package is a JavaScript library for asynchronous form validation. It allows developers to define validation rules and apply them to data objects, handling both synchronous and asynchronous validation scenarios. It is commonly used in web development to validate form inputs on the client side before submitting data to a server.

What are async-validator's main functionalities?

Schema Definition and Validation

Define a schema with validation rules and apply it to a data object. The example code defines a rule that requires a string with a minimum length of 5 characters and validates the value 'Hello World' against this rule.

{"rule": {"type": "string", "required": true, "min": 5}, "value": "Hello World"}

Custom Validators

Create custom validation functions for more complex or specific validation scenarios. The example code shows a custom validator that checks if the value is equal to 'expected' and returns an error if it is not.

{"rule": {"validator": "(rule, value, callback) => { if (value !== 'expected') { callback(new Error('Value is not expected!')); } else { callback(); } }"}, "value": "unexpected"}

Asynchronous Validation

Perform asynchronous operations within your validation rules. The example code demonstrates an asynchronous validator that resolves if the value is 'async' and rejects with an error message otherwise.

{"rule": {"validator": "(rule, value) => new Promise((resolve, reject) => { setTimeout(() => { if (value === 'async') { resolve(); } else { reject('Value must be async'); } }, 1000); })"}, "value": "async"}

Other packages similar to async-validator

FAQs

Package last updated on 17 Jun 2022

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