Skip to content
/ schm Public

Composable schemas for JavaScript and Node.js

License

Notifications You must be signed in to change notification settings

diegohaz/schm

Repository files navigation

Build StatusCoverage Status



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 withschmonRunKit(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.

Packages

schmrepository is amonorepomanaged bylerna.Click on package name to see specificdocumentation.

Package Version Description
schm NPM version The main package
schm-computed NPM version Adds computed parameters to schemas
schm-express NPM version Express middlewares to handle querystring and response body
schm-koa NPM version Koa middlewares to handle querystring and response body
schm-methods NPM version Adds methods to parsed schema objects
schm-mongo NPM version Parses values to MongoDB queries
schm-translate NPM version Translates values keys to schema keys

Contributing

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:

  1. Make sure to lint the code:yarn lintorlerna run lint;
  2. Make sure tests are passing:yarn testorlerna run test;

License

MIT ©Diego Haz