open-index/open-npm huggingface dataset:
npm package: @micromq/expect
Description: Simple middleware for validate params.
Author: Mikhail Semin
Latest version: 1.0.2

# @micromq/expect

Simple middleware for validate params.

## Install

```sh
$ npm i @micromq/expect
```

## Tests

```sh
$ npm test
```

## Usage

```js
const MicroMQ = require('micromq');
const paramsCollector = require('@micromq/params-collector');
const expect = require('@micromq/expect');

const app = new MicroMQ({
  name: process.env.MICROSERVICE_NAME,
  rabbit: {
    url: process.env.RABBIT_URL,
  },
});

app.use(paramsCollector);

app.use(async (req, res, next) => {
  try {
    await next();
  } catch (err) {
    console.error(err.status);    // 400
    console.error(err.message);   // 'city is invalid'
  }
});

app.post(
  '/create',
  expect({
    // required, string type
    name: String,
    
    // required, string/number type, must be greater than 18
    age: {
      // may a string or a number
      type: [String, Number],
      required: true,
      validate: age => +age > 18,
    },
    
    // not required, string type, length must be greater than 10
    city: {
      type: String,
      validate: city => city.length > 10,
    },
  }),
  (req, res) => {
    // creating something good...
  },
);

app.start();
```
npm package: @micromq/params-collector
Description: Middleware for collect params in one object (params = params + query + body).
Author: Mikhail Semin
Latest version: 1.0.0

# @micromq/params-collector

Middleware for collect params in one object (params = params + query + body).

## Install

```sh
$ npm i @micromq/params-collector
```

## Usage

```js
const MicroMQ = require('micromq');
const paramsCollector = require('@micromq/params-collector');

const app = new MicroMQ({
  name: process.env.MICROSERVICE_NAME,
  rabbit: {
    url: process.env.RABBIT_URL,
  },
});

app.use(paramsCollector);

app.post('/', (req, res) => {
  /*
  
    before:

      req.params = { id: 5 };
      req.query = { sort: 'id' };
      req.body = { name: 'John' };


    after:

      req.params = { sort: 'id', id: 5, name: 'John' };  

   */
});

app.start();
```