SkillAgentSearch skills...

Schm

Composable schemas for JavaScript and Node.js

Install / Use

/learn @diegohaz/Schm
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<img src="logo/logo.svg" width="200">

Build Status Coverage Status

<br> <hr> <p align="center"> If you find this useful, please don't forget to star ⭐️ the repo, as this will help to promote the project.<br> Follow me on <a href="https://twitter.com/diegohaz">Twitter</a> and <a href="https://github.com/diegohaz">GitHub</a> to keep updated about this project and <a href="https://github.com/diegohaz?tab=repositories">others</a>. </p> <hr> <br><br>

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

Related Skills

View on GitHub
GitHub Stars513
CategoryDevelopment
Updated4mo ago
Forks23

Languages

JavaScript

Security Score

97/100

Audited on Nov 17, 2025

No findings