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

express-validator

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-validator - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

test/optional.js

12

lib/express_validator.js

@@ -141,2 +141,14 @@ /*

methods['optional'] = function() {
if (value !== undefined) {
return methods;
}
var dummyMethods = [];
for (var methodName in methods) {
dummyMethods[methodName] = function() { return dummyMethods; };
}
return dummyMethods;
};
return methods;

@@ -143,0 +155,0 @@ }

2

package.json

@@ -11,3 +11,3 @@ {

],
"version": "2.4.0",
"version": "2.5.0",
"homepage": "https://github.com/ctavan/express-validator",

@@ -14,0 +14,0 @@ "repository": {

@@ -105,2 +105,28 @@ # express-validator

####`customValidators`
_{ "validatorName": function(value, [additional arguments]), ... }_
The `customValidators` option can be used to add additional validation methods as needed. This option should be an `Object` defining the validator names and associated validation functions.
Define your custom validators:
```javascript
app.use(expressValidator({
customValidators: {
isArray: function(value) {
return Array.isArray(value);
},
gte: function(param, num) {
return param >= num;
}
}
}));
```
Use them with their validator name:
```javascript
req.checkBody('users', 'Users must be an array').isArray();
req.checkQuery('time', 'Time must be an integer great than or equal to 5').isInt().gte(5)
```
### Validation errors

@@ -146,2 +172,11 @@

### Optional input
You can use the `optional()` method to check an input only when the input exists.
```javascript
req.checkBody('email').optional().isEmail();
//if there is no error, req.body.email is either undefined or a valid mail.
```
### Nested input data

@@ -197,10 +232,4 @@

You can add your own validators using `expressValidator.validator.extend(name, fn)`
You can add your own validators using the `customValidators` option. See [Middleware Options](#middleware-options) for usage details.
```javascript
expressValidator.validator.extend('isFinite', function (str) {
return isFinite(str);
});
```
## Changelog

@@ -207,0 +236,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