Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/corentinth/garant
Simple and lightweight javascript object schema validation library.
https://github.com/corentinth/garant
assert check javascript library object type validation
Last synced: about 1 month ago
JSON representation
Simple and lightweight javascript object schema validation library.
- Host: GitHub
- URL: https://github.com/corentinth/garant
- Owner: CorentinTh
- License: mit
- Created: 2020-02-24T16:14:50.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T08:21:01.000Z (about 2 years ago)
- Last Synced: 2024-12-18T22:31:23.858Z (about 1 month ago)
- Topics: assert, check, javascript, library, object, type, validation
- Language: TypeScript
- Homepage:
- Size: 305 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Simple and lightweight javascript object schema validation library.
## Description
* **Lightweight**: when bundled with rollup and terser, the output weight less than 2kB (vs ~167kB for [@hapi/joi](https://www.npmjs.com/package/@hapi/joi), 80 times ratio!)
* **Modular**: easily create new checkers (see [here](#road_map))
* **Typescript support**## Installation
**Garant** can be installed using yarn or npm.
```shell
npm install garant
# or
yarn add garant
```## Usage
```javascript
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: '[email protected]',
info: {
age: 22,
height: 165
}
};const results = validator.check(object);
// {
// hasError: false,
// messages: [],
// data: {
// username: 'Jane',
// email: '[email protected]',
// info: {
// age: 22,
// height: 165
// }
// }
// }```
## Road map
- ~~**Required** checker~~
- ~~**Type** checker~~
- ~~**Children** checker~~
- ~~**Default** checker (set default value if undefined)~~
- Improve documentation
- **Regex** checker
- **Length** (min, max) checker
- **Array content** checkerWant to add your *checker*? Simply create yours in the [src/checkers](./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](//corentin-thomasset.fr).## License
This project is under the [MIT license](./LICENSE.md).