Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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&currency_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)