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