Full-Stack Validator
A simple validation library for server and client side applications.
Features
- Tiny footprint (2.27 kB / gzip: 931 B)
- Universal (can be used in server and client side)
- Out of the box basic validation rules
- Extensible (add your own rules)
Installation
npm install --save fullstack-validator
Usage
Simple Example
; const v = /* pass custom rules here */; { // Inputs to validate const inputs = data: value: email check: "email" message: "Please enter valid email." data: value: password length: 6 check: "lengthMin" message: "Password needs to be minimum 6 characters long" ; // Validate try v; catch error throw errormessage; // Create user try const user = await User; if user return data: user message: "User created successfully." ; catch error throw `An error occurred. `; }
Custom rules
; const rules = { const regexp = /^$/; return regexp; }; const v = rules; { // Inputs to validate const inputs = data: value: creditCardNumber check: "isValidCreditCard" message: "Please enter valid credit card." ; // Validate try v; catch error throw errormessage; // Create payment try const payment = await Payment; if payment return data: payment message: "User created successfully." ; catch error throw `An error occurred. `; }
Author
Contributors
- [YOUR NAME HERE] - Feel free to contribute to the codebase by resolving any open issues, refactoring, adding new features, writing test cases or any other way to make the project better and helpful to the community. Feel free to fork and send pull requests.
Donate
If you liked this project, you can donate to support it ❤️
License
Copyright (c) 2019 Atul Yadav http://github.com/atulmy
The MIT License (http://www.opensource.org/licenses/mit-license.php)