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

celebrate

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

celebrate - npm Package Compare versions

Comparing version 7.0.2 to 7.0.3

67

lib/index.js

@@ -24,21 +24,23 @@ 'use strict';

}
Joi.validate(req[source], spec, options, (err, value) => {
if (value !== undefined) {
const descriptor = Object.getOwnPropertyDescriptor(req, source);
/* istanbul ignore next */
if (descriptor && descriptor.writable) {
req[source] = value;
} else {
Object.defineProperty(req, source, {
get () { return value; }
});
}
const result = Joi.validate(req[source], spec, options);
const value = result.value;
const err = result.error;
if (value !== undefined) {
const descriptor = Object.getOwnPropertyDescriptor(req, source);
/* istanbul ignore next */
if (descriptor && descriptor.writable) {
req[source] = value;
} else {
Object.defineProperty(req, source, {
get () { return value; }
});
}
if (err) {
err[CELEBRATED] = true;
err._meta = { source };
return next(err);
}
return next(null);
});
}
if (err) {
err[CELEBRATED] = true;
err._meta = { source };
return next(err);
}
return next(null);
};

@@ -51,3 +53,19 @@ };

const validateBody = validateSource('body');
const maybeValidateBody = (config, callback) => {
const method = config.req.method.toLowerCase();
if (method === 'get' || method === 'head') {
return callback(null);
}
validateBody(config, callback);
};
const REQ_VALIDATIONS = [
validateHeaders,
validateParams,
validateQuery,
maybeValidateBody
];
const isCelebrate = (err) => {

@@ -72,14 +90,3 @@ if (err != null && typeof err === 'object') { // eslint-disable-line eqeqeq

const middleware = (req, res, next) => {
Series(null, [
validateHeaders,
validateParams,
validateQuery,
(config, callback) => {
const method = config.req.method.toLowerCase();
if (method === 'get' || method === 'head') {
return callback(null);
}
validateBody(config, callback);
}
], {
Series(null, REQ_VALIDATIONS, {
req,

@@ -86,0 +93,0 @@ options: joiOpts,

{
"name": "celebrate",
"version": "7.0.2",
"version": "7.0.3",
"description": "A joi validation middleware for Express.",

@@ -9,3 +9,4 @@ "main": "lib/index.js",

"lint": "belly-button -i 'lib/*.js' -f",
"test": "npm run lint && jest --ci"
"test": "npm run lint && jest --ci",
"benchmark": "node benchmarks/index"
},

@@ -38,2 +39,3 @@ "repository": {

"belly-button": "4.x.x",
"benchmark": "2.1.4",
"body-parser": "1.18.2",

@@ -40,0 +42,0 @@ "expect": "21.2.x",

@@ -57,3 +57,3 @@ ![Celebrate](https://github.com/continuationlabs/celebrate/raw/master/images/logo.png)

// if missing or not the correct format, respond with an error
app.use(Celebrate({
app.use(celebrate({
headers: Joi.object({

@@ -60,0 +60,0 @@ token: Joi.string().required().regex(/abc\d{3}/)

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