Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/molnarmark/schemr
📃 A tiny, unopinionated Schema definition & checker package
https://github.com/molnarmark/schemr
schema schema-builder schema-validation schemr
Last synced: about 1 month ago
JSON representation
📃 A tiny, unopinionated Schema definition & checker package
- Host: GitHub
- URL: https://github.com/molnarmark/schemr
- Owner: molnarmark
- License: mit
- Created: 2018-08-21T22:57:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-21T23:07:29.000Z (over 6 years ago)
- Last Synced: 2024-11-09T09:41:24.261Z (about 1 month ago)
- Topics: schema, schema-builder, schema-validation, schemr
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📃 Schemr
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)
[![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)> The Ultimate Tiny schema validation package.
### Getting Started
```
npm install --save schemr
```### Usage
You can find a working example in `tester.js`.
```javascript
const { Schemr, check } = require('schemr');const testSchema = new Schemr('human-being', {
name: Schemr.field,
age: Schemr.field,
job: Schemr.field,
});console.log(testSchema.getName());
//=> human-being
console.log(testSchema.getFields());
//=> { name: 'SchemrField', age: 'SchemrField', job: 'SchemrField' }
console.log(testSchema.toJSON());
/*=>
{
"name": "human-being",
"fields": {
"name": "SchemrField",
"age": "SchemrField",
"job": "SchemrField"
}
}
*/const testData = {
name: 'Mark',
extraFieldForNoReason: false,
};const checkedObject = check(testSchema, testData);
console.log(checkedObject);
//=> { name: 'Mark', age: 21, job: undefined }const checkedObject2 = check(testSchema, testData, {
replaceEmptyFieldsWith: 'unfilled',
});console.log(checkedObject2);
//=> { name: 'Mark', age: 'unfilled', job: 'unfilled' }
```### License
- MIT### Roadmap
*TODO*