https://github.com/aeberdinelli/schemy-ts
A Schemy version with TypeScript support, it's a separated project to keep some backwards compatibility issues away.
https://github.com/aeberdinelli/schemy-ts
Last synced: about 1 year ago
JSON representation
A Schemy version with TypeScript support, it's a separated project to keep some backwards compatibility issues away.
- Host: GitHub
- URL: https://github.com/aeberdinelli/schemy-ts
- Owner: aeberdinelli
- Created: 2021-06-03T10:01:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-13T22:27:03.000Z (over 2 years ago)
- Last Synced: 2024-09-18T06:15:48.039Z (almost 2 years ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/schemy-ts
- Size: 71.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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!**
- This is the TypeScript version of [Schemy](https://github.com/aeberdinelli/schemy).
## Missing features
All features are shared with the main version, except for the short-style declaration:
```typescript
// This is not available :(
const schema = new Schemy({
name: String
});
// You need to declare it like this
const schema = new Schemy({
name: { type: String }
});
```
## Unique features
Available only in the TS version
```typescript
// Schemy needs to be imported this way
import { Schemy } from 'schemy-ts';
// For the following examples we are using the following type
type User = {
name: string;
age: number;
};
```
#### Create typed schema
Use this to make sure you declare all the properties in the schema for your Type:
```typescript
// This will give an error because `age` is defined in the type but not in the schema
const UserSchema = Schemy.schema({
name: { type: String }
});
```
#### Create strict typed schema
This is just the same as the typed schema but the resulting Schemy instance will be `strict`.
```typescript
// You can also do this to make the schema strict
const UserSchema = Schemy.strict({
name: { type: String }
});
```
#### Validate and return typed body
You can validate and return the body with the specified type. This works extremely well with [VS Code](https://code.visualstudiSco.com/) intellisense.
```typescript
const user: User = await Schemy.validate({ name: 'schemy' });
```
#### Return typed body
This is similar to the previous example, but in this case you are not validating. You're just returning the last validated input.
```typescript
const user: User = Schemy.getBody();
```
## And more...
To see all the features, please visit the [Schemy wiki](https://github.com/aeberdinelli/schemy/wiki).