z-validify
v1.0.7
Published
A lightweight state validation library for React applications.
Downloads
2
Maintainers
Readme
z-validify
z-validify
is a lightweight client-side payload validation library designed for React applications. This library ensures that your state objects are validated efficiently, minimizing load on the backend by performing validations on the client side.
Features
- Lightweight: At just 1.1 kB, z-validify adds minimal impact to your bundle size.
- Simple API: Provides a straightforward function to validate state objects.
- Automatic Detection: Automatically detects and reports null, undefined, and empty string values in state objects.
- Ease of Use: Quickly integrate into your project to enhance form validations.
Installation
Install z-validify via npm:
npm install z-validify
API
- validatePayload(state)
- Description: Validates a state object to ensure all fields are non-null, defined, and non-empty.
Parameters:
- state (object): The state object to validate.
- Returns: An object containing:
- isValid (boolean): Indicates if the state object is valid.
- message (string): A message indicating which fields, if any, are invalid.
Installation
npm install z-validify
Usage :
import validatePayload from 'z-validify'
const state = {
name: 'John Doe',
age: 30,
email: '[email protected]',
address: '' // This field is empty
}
const validation = validatePayload(state);
if (!validation.isValid) {
console.error(validation.message);
} else {
console.log('State is valid!');
}