Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dat-middleware

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-middleware - npm Package Compare versions

Comparing version 1.8.1 to 1.9.0

test/each.js

25

lib/RequestData.js

@@ -378,2 +378,27 @@ var error = require('./error');

/**
* delete keys from data object
* @param {...key} string - keys on the request data to delete.
*/
RequestData.prototype.each = function (/* middlewares */) {
var self = this;
var req = require('../index').req;
if (this._keys.length > 1) {
throw new Error('cannot be used with multiple keys');
}
var key = this._keys[0];
var middlewares = Array.prototype.slice.call(arguments);
if (middlewares.length === 0) {
throw new Error('atleast one middleware is required');
}
return function (req, res, next) {
var arr = keypather.get(req, self.keypath(key));
if (!Array.isArray(arr)) {
throw new Error('keypath "'+key+'" is not an array');
}
var args = [arr].concat(middlewares);
flow.each.apply(flow, args)(req, res, next);
};
};
/*************** CONDITIONALS ***************/

@@ -380,0 +405,0 @@ /*************** CONDITIONALS ***************/

4

package.json
{
"name": "dat-middleware",
"version": "1.8.1",
"version": "1.9.0",
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware",

@@ -42,3 +42,3 @@ "main": "index.js",

"map-utils": "~0.4.0",
"middleware-flow": "^0.5.0"
"middleware-flow": "^0.6.0"
},

@@ -45,0 +45,0 @@ "devDependencies": {

@@ -229,2 +229,24 @@ # dat-middleware [![Build Status](https://travis-ci.org/tjmehta/dat-middleware.png?branch=master)](https://travis-ci.org/tjmehta/dat-middleware)

# Flow Control
## each()
iterates through a series of middlewares (in parallel) for each item in an array
```js
var mw = require('dat-middleware');
var app = require('express')();
// a body of { arr: [1,2,3] }
app.use(mw.body('arr').each(
function (eachReq, res, next) {
// eachReq prototypically inherits from the original req
// (get gets from req, set only sets to eachReq)
},
function (item, req, eachReq, res, next) {
// if five arguments are accepted the current item and the origin req are passed
}
));
```
# Conditionals (flow control):

@@ -231,0 +253,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc