npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tcomb-validation-middleware

v1.1.0

Published

Express middleware to validate requests using the tcomb & tcomb validation library

Readme

Tcomb Validation Middleware

Express Middleware that performs runtime type checking of objects. It is primerily meant for type checking in development.

Build CircleCI

Tests Coverage Status

Installation

npm i tcomb-validation-middleware

Usage

Use the library tcomb to define the model of the data structure

const t = require('tcomb');

const test = t.struct({
  test: t.String,
  bool: t.Boolean,
});

module.exports = {
  test,
};

Then add as middleware to the route of the endpoint

const t = require('tcomb-validation-middleware');

... //Express setup stuff

app.post('/test', t(test), (req, res) => {
  res.send({ message: 'schema was obviously valid' });
});

The module also accepts an options object like so

t(test,{ active: true, verboseErrors: false })

Tests

To run the tests do

npm test

Performance

Applying strict type validation to your server will decrease it's performance slightly under heavy loads but the tradeoff of very usefull error messages can make it worth it. If in production in an environment where you control the client it's very easy to reuse your tcomb schemas. This allows you to move the validation client side without much development overhead.

The results in the table below are generated using artillery.

| First Header | Scenarios launched | Scenarios completed | Requests completed | RPS sent | Request latency | min | max | median | p95 | p99 | Scenario duration | min | max | median | p95 | p99 | | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------- | | Enabled | 1000 | 1000 | 20000 | 970.87 | -> | 0.3 | 41.4 | 0.4 | 2.8 | 11.7 | -> | 14.5 | 447.2 | 18.7 | 98 | 384.6 | | Disabled | 1000 | 1000 | 20000 | 970.4 | -> | 0.2 | 24.2 | 0.4 | 1.6 | 3.5 | -> | 11 | 124.8 | 16.6 | 48.6 | 108.1 |

If you would like to verify them clone the module from git then run the following commands.

cd express-tcomb-validation-middleware
npm install
node ./test/lib/index.js

Then in another window run

npm install -g artillery
artillery quick --count 1000 -n 20 http://localhost:4444/test/on/test/hi
artillery quick --count 1000 -n 20 http://localhost:4444/test/off/test/hi

Built with

Contributing

Make a github issue if you have any feature requests or problems. I welcome pull requests as long as they have the relevent tests included.

License

This project is licensed under the MIT License - see the LICENSE.md file for details