If you find this useful, please don't forget to star ⭐️ the repo, as this will help to promote the project.
Follow me onTwitterandGitHubto keep updated about this project andothers.
schmis a library for creating immutable, composable, parseable and validatable (yeah, many *ables) schemas in JavaScript and Node.js. That's highly inspired byfunctional programmingparadigm.
Play withschm
onRunKit(click onClone and edit this documentat the bottom and skip login if you want).
constschema=require('schm')
constuserSchema=schema({
name:String,
age:{
type:Number,
min:18,
},
})
userSchema.parse({
name:'Haz',
age:'27',
})
awaituserSchema.validate({
name:'Jeane',
age:10,
})
Output:
// parsed
{
name:'Haz',
age:27,
}
// validate error
[
{
param:'age',
value:10,
validator:'min',
min:18,
message:'age must be greater than or equal 18',
},
]
The way you declare the schema object is very similar tomongoose Schemas.So, refer to their docs to learn more.
schm
repository is amonorepomanaged bylerna.Click on package name to see specificdocumentation.
Package | Version | Description |
---|---|---|
schm |
The main package | |
schm-computed |
Adds computed parameters to schemas | |
schm-express |
Express middlewares to handle querystring and response body | |
schm-koa |
Koa middlewares to handle querystring and response body | |
schm-methods |
Adds methods to parsed schema objects | |
schm-mongo |
Parses values to MongoDB queries | |
schm-translate |
Translates values keys to schema keys |
When submitting an issue, put the related package between brackets in the title:
[methods] Something wrong is not right#related to schm-methods
[translate] Something right is not wrong#related to schm-translate
Something wrong is wrong#general issue
PRs are welcome. You should have a look atlernato understand how this repository works.
After cloning the repository, runyarn
.That will install all the project dependencies, including the packages ones.
Before submitting a PR:
- Make sure to lint the code:
yarn lint
orlerna run lint
; - Make sure tests are passing:
yarn test
orlerna run test
;
MIT ©Diego Haz