• Stars
    star
    513
  • Rank 86,178 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Composable schemas for JavaScript and Node.js

Build Status Coverage Status



If you find this useful, please don't forget to star ⭐️ the repo, as this will help to promote the project.
Follow me on Twitter and GitHub to keep updated about this project and others.




schm is a library for creating immutable, composable, parseable and validatable (yeah, many *ables) schemas in JavaScript and Node.js. That's highly inspired by functional programming paradigm.

Play with schm on RunKit (click on Clone and edit this document at the bottom and skip login if you want).

const schema = require('schm')

const userSchema = schema({
  name: String,
  age: {
    type: Number,
    min: 18,
  },
})

userSchema.parse({
  name: 'Haz',
  age: '27',
})

await userSchema.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 to mongoose Schemas. So, refer to their docs to learn more.

Packages

schm repository is a monorepo managed by lerna. Click on package name to see specific documentation.

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 at lerna to understand how this repository works.

After cloning the repository, run yarn. That will install all the project dependencies, including the packages ones.

Before submitting a PR:

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

License

MIT Β© Diego Haz

More Repositories

1

constate

React Context + State
TypeScript
3,924
star
2

arc

React starter kit based on Atomic Design
JavaScript
2,914
star
3

rest

REST API generator with Node.js, Express and Mongoose
JavaScript
1,788
star
4

generact

Generate React components by replicating your own
JavaScript
1,482
star
5

awesome-react-context

😎 A curated list of stuff related to the new React Context API
JavaScript
917
star
6

styled-tools

Useful interpolated functions for CSS-in-JS
JavaScript
802
star
7

reuse

♻️ Reuse React components to create new ones
TypeScript
495
star
8

singel

Single Element Pattern
JavaScript
408
star
9

nod

Node.js module generator/boilerplate with Babel, Jest, Flow, Documentation and more
JavaScript
360
star
10

redux-saga-thunk

Dispatching an action handled by redux-saga returns promise
JavaScript
221
star
11

styled-theme

Extensible theming system for styled-components πŸ’…
JavaScript
182
star
12

querymen

Querystring parser middleware for MongoDB, Express and Nodejs (MEN)
JavaScript
129
star
13

parse-prop-types

Parses React prop-types into a readable object
JavaScript
69
star
14

bodymen

Body parser middleware for MongoDB, Express and Nodejs (MEN)
JavaScript
47
star
15

list-react-files

List React component files inside a directory
JavaScript
25
star
16

redux-saga-social-login

Facebook/Google login implementation with redux-saga
JavaScript
25
star
17

mongoose-keywords

Mongoose plugin that generates a keywords path combining other paths values
JavaScript
22
star
18

redux-modules

A modular approach to better organize redux stuff (not another library)
JavaScript
21
star
19

coolors-to-hex

Get hexadecimal values from a coolors url
JavaScript
18
star
20

generator-rest-example

A fully commented RESTful API example generated with generator-rest
JavaScript
18
star
21

styled-selector

Get static CSS(-in-JS) selectors from React components
TypeScript
17
star
22

webpack-blocks-split-vendor

A webpack block that splits vendor javascript into separated bundle
JavaScript
15
star
23

webpack-blocks-happypack

A webpack block that adds happypack support to your webpack config
JavaScript
12
star
24

redux-form-submit

Adds an async submit action creator to redux-form
JavaScript
9
star
25

webpack-spawn-plugin

A webpack plugin that runs child_process.spawn within compilation
JavaScript
7
star
26

waterfall-grid

A Polymer wrapper element for waterfall.js, a 1KB Javascript library for Pinterest-like grids.
HTML
7
star
27

webpack-blocks-server-source-map

A webpack block that adds source map support to server bundle
JavaScript
5
star
28

yo

A Yeoman generator for generating next generation of Yeoman generators
JavaScript
5
star
29

webpack-assets-by-type-plugin

A webpack plugin that save assets by type
JavaScript
5
star
30

arc-universal-redux

Universal Redux version of ARc boilerplate
JavaScript
5
star
31

webpack-sort-chunks

Sorts webpack chunks by dependency
JavaScript
4
star
32

webpack-child-config-plugin

A webpack plugin that runs/watches another config
JavaScript
4
star
33

rest-api

REST API Boilerplate with Mongoose, Express and Nodejs
JavaScript
4
star
34

rich-param

An object with name and value which accepts pluggable methods as formatters or validators
JavaScript
3
star
35

reakit-code-lab

TypeScript
3
star
36

arc-fullstack

Fullstack version of ARc boilerplate
JavaScript
3
star
37

is-git-rev

Verify if a string is a git-rev hash
JavaScript
3
star
38

mongoose-create-unique

Mongoose plugin to create a document or return the existing one based on the unique index
JavaScript
3
star
39

divisa

A game about war and peace.
JavaScript
2
star
40

eyeport

Collection of useful methods to deal with element and viewports in DOM
JavaScript
2
star
41

alpha-bank

JavaScript
2
star
42

guild

Just a social network prototype made with jQuery
HTML
2
star
43

adjacente

Blog para disciplina ExpansΓ£o dos Sentidos
JavaScript
1
star
44

radiotoca

A PHP web radio with Twitter integration
PHP
1
star
45

clone

JavaScript
1
star
46

diegohaz

1
star
47

hear-parse

JavaScript
1
star
48

hear-api

JavaScript
1
star
49

diegohaz.com

JavaScript
1
star