Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aeberdinelli/schemy
Schemy is an extremely simple, lightweight schema validation library.
https://github.com/aeberdinelli/schemy
javascript joi json library mongoose node nodejs schema typescript validation
Last synced: 1 day ago
JSON representation
Schemy is an extremely simple, lightweight schema validation library.
- Host: GitHub
- URL: https://github.com/aeberdinelli/schemy
- Owner: aeberdinelli
- Created: 2020-06-29T01:03:30.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T22:01:07.000Z (9 months ago)
- Last Synced: 2024-10-28T22:21:54.680Z (17 days ago)
- Topics: javascript, joi, json, library, mongoose, node, nodejs, schema, typescript, validation
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/schemy
- Size: 332 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
### [Docs ๐](https://github.com/aeberdinelli/schemy/wiki) ยท [Plugins ๐งฉ](https://github.com/aeberdinelli/schemy/wiki/List-of-plugins) ยท [Changelog ๐](https://github.com/aeberdinelli/schemy/releases) ยท [Donate ๐ฐ](https://www.paypal.com/donate/?cmd=_donations&business=aeberdinelli%40gmail.com&item_name=Schemy+library¤cy_code=USD&source=url)
Schemy is an extremely simple, lightweight yet powerful schema validation library. Perfect for lightweight-oriented projects like cloud functions where size and speed are key features. **It weights less than 18 KB!**
## Usage
Install using npm: `npm install --save schemy`.
Then, create a schema with the desired properties and their types:```javascript
const Schemy = require('schemy');const characterSchema = new Schemy({
'name': {
type: String,
required: true
}
});// Validate against input data
if (!characterSchema.validate(someData)) {
characterSchema.getValidationErrors(); // => [ 'Missing required property name' ]
}// You can also validate asynchronously
await Schemy.validate(someData, characterSchema);
```## Plugins
Schemy can be easily extended with new functionality. For example, this adds a feature to reference properties within the schema.```javascript
// Require the plugin
const ReferenceSupport = require('schemy-reference-support');// Call Schemy.extend() with the plugin or with an array of plugins
Schemy.extend(ReferenceSupport);new Schemy({
password: String,
confirm: Schemy.$ref('password')
});
```You can check the whole list of [available plugins in the wiki โ](https://github.com/aeberdinelli/schemy/wiki/List-of-plugins)
## API
#### Static methods
- [Schemy(object)](https://github.com/aeberdinelli/schemy/wiki#-usage) - Takes an object with the desired structure to validate later
- [Schemy.validate(data, schema)](https://github.com/aeberdinelli/schemy/wiki/Async-validation#async-validation) - Asynchronously validates some data against the passed schema
- [Schemy.extend(Plugin)](https://github.com/aeberdinelli/schemy/wiki/Using-plugins) - Load one or multiple plugins into Schemy#### Instance methods
- [validate(data)](https://github.com/aeberdinelli/schemy/wiki/Synchronous-validation) - Validates the schema
- [getValidationErrors()](https://github.com/aeberdinelli/schemy/wiki/getValidationErrors) - Returns generated errors from the last validation
- [getBody(includeAll = false)](https://github.com/aeberdinelli/schemy/wiki/getBody(includeAll-=-false)) - Returns the last validated input
[Full documentation โ๏ธ](https://github.com/aeberdinelli/schemy/wiki)