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
6 years ago
1.2.1
6 years ago
0.0.0-4d458f3
6 years ago
1.2.0
6 years ago
0.0.0-c5cf69a
6 years ago
0.0.0-294bf8f
6 years ago
0.0.0-fcf154a
6 years ago
0.0.0-86f50df
6 years ago
0.0.0-35aabdb
6 years ago
1.1.1
6 years ago
0.0.0-7f0fc8e
6 years ago
0.0.0-0cb5a65
6 years ago
0.0.0-cfad9ed
6 years ago
1.1.0
6 years ago
0.0.0-de1220c
6 years ago
0.0.0-cedc78d
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago
0.0.0
6 years ago
0.0.0-dd851c0
6 years ago
0.0.0-746a85e
6 years ago
0.0.0-65a2bfb
6 years ago
0.0.0-cb254db
6 years ago
0.0.0-2fb5109
6 years ago
0.0.0-160fbec
6 years ago