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

dat-middleware

Package Overview
Dependencies
Maintainers
1
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.2.0 to 1.3.0

test/matches.js

13

lib/RequestData.js

@@ -218,2 +218,13 @@ var error = require('./error');

/**
* @method
* @param {regexp} re - keys sh.
*/
RequestData.prototype.matches = function (re) {
if (!re) {
throw new Error('match requires a regexp');
}
this.validate(validations.matches(re));
return this;
};
/**
* assert keys exist

@@ -288,3 +299,3 @@ * @method function

if (typeof data[key] === 'string') {
data[key] = keypather.get(req, data[key]) || data[key];
data[key] = keypather.get(req, data[key]) || data[key];
}

@@ -291,0 +302,0 @@ });

@@ -33,3 +33,12 @@ var utils = require('map-utils');

};
},
matches: function (re) {
return function (val) {
if (!re.test(val)) {
var err = error('should match '+re.toString());
err.val = val;
return err;
}
};
}
};

2

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

@@ -5,0 +5,0 @@ "main": "index.js",

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

## matches(regexp)
requires the keys are an instance of the specified class (if they exist), and nexts a 400 error if one is not
```js
var mw = require('dat-middleware');
var app = require('express')();
// requires that req.body.key1 and req.body.key2 match the regexp *if they exist*
app.use(mw.body('key1, key2').matches(/^hello/));
// example error:
// 400 { message: body parameter "key1" must match /^hello/ }
```
## validate(validation)

@@ -126,0 +140,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