1.2.1 • Published 5 years ago
garant v1.2.1
Simple and lightweight javascript object schema validation library.
Installation
Garant can be installed using yarn or npm.
npm install garant
# or
yarn add garant
Usage
import {Validator} from 'garant';
// or
const {Validator} = require('garant');
const schema = {
username: {
type: 'string',
required: true
},
email: {
type: 'string',
},
info: {
type: 'object',
children:{
age: {
type: 'number',
},
height: {
type: 'number',
}
}
}
};
const validator = new Validator(schema);
const object = {
username: 'Jane',
email: 'jane@example.com',
info: {
age: 22,
height: 165
}
};
const results = validator.check(object);
// {
// hasError: false,
// messages: [],
// data: {
// username: 'Jane',
// email: 'jane@example.com',
// info: {
// age: 22,
// height: 165
// }
// }
// }
Road map
Required checkerType checkerChildren checker- Improve documentation
- Default checker (set default value if undefined)
- Regex checker
- Length (min, max) checker
- Array content checker
Want to add your checker? Simply create yours in the src/checkers directory and register it in the Validator class. Submit your pull request!
Contribute
Pull requests are welcome ! Feel free to contribute.
Credits
Coded with ❤️ by Corentin Thomasset.
License
This project is under the MIT license.
0.0.0-1f94993
5 years ago
0.0.0-c4329e6
5 years ago
0.0.0-b37d862
5 years ago
1.2.1
5 years ago
0.0.0-4d458f3
5 years ago
1.2.0
5 years ago
0.0.0-c5cf69a
5 years ago
0.0.0-294bf8f
5 years ago
0.0.0-fcf154a
5 years ago
0.0.0-86f50df
5 years ago
0.0.0-35aabdb
5 years ago
1.1.1
5 years ago
0.0.0-7f0fc8e
5 years ago
0.0.0-0cb5a65
5 years ago
0.0.0-cfad9ed
5 years ago
1.1.0
5 years ago
0.0.0-de1220c
5 years ago
0.0.0-cedc78d
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago
0.0.0
5 years ago
0.0.0-dd851c0
5 years ago
0.0.0-746a85e
5 years ago
0.0.0-65a2bfb
5 years ago
0.0.0-cb254db
5 years ago
0.0.0-2fb5109
5 years ago
0.0.0-160fbec
5 years ago