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

celebrate

Package Overview
Dependencies
Maintainers
1
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.6 to 8.0.0

2

lib/index.d.ts

@@ -26,3 +26,3 @@ import { ErrorRequestHandler, RequestHandler } from 'express';

*/
export const Joi: joi
export const Joi: joi;

@@ -29,0 +29,0 @@ /**

@@ -1,3 +0,1 @@

'use strict';
const Series = require('fastseries')({ results: true });

@@ -7,14 +5,16 @@ const Assert = require('assert');

const EscapeHtml = require('escape-html');
const validations = require('./schema');
const validations = require('./schema');
const CELEBRATED = Symbol('isCelebrate');
const DEFAULTS = {
escapeHtml: true
escapeHtml: true,
};
const validateSource = (source) => {
return (config, next) => {
const req = config.req;
const options = config.options;
const rules = config.rules;
const validateSource = source =>
(config, next) => {
const {
req,
options,
rules,
} = config;
const spec = rules.get(source);

@@ -26,4 +26,6 @@

const result = Joi.validate(req[source], spec, options);
const value = result.value;
const err = result.error;
const {
value,
error: err,
} = result;

@@ -37,3 +39,3 @@ if (value !== undefined) {

Object.defineProperty(req, source, {
get () { return value; }
get() { return value; },
});

@@ -49,3 +51,2 @@ }

};
};

@@ -63,3 +64,3 @@ const validateHeaders = validateSource('headers');

validateBody(config, callback);
return validateBody(config, callback);
};

@@ -71,7 +72,7 @@

validateQuery,
maybeValidateBody
maybeValidateBody,
];
const isCelebrate = (err) => {
if (err != null && typeof err === 'object') { // eslint-disable-line eqeqeq
if (err != null && typeof err === 'object') {
return err[CELEBRATED] || false;

@@ -88,7 +89,5 @@ }

const keys = Object.keys(schema);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
Object.keys(schema).forEach((key) => {
rules.set(key, Joi.compile(schema[key]));
}
});
const middleware = (req, res, next) => {

@@ -98,3 +97,3 @@ Series(null, REQ_VALIDATIONS, {

options: joiOpts,
rules
rules,
}, next);

@@ -108,28 +107,25 @@ };

const errors = () => {
return (err, req, res, next) => {
if (isCelebrate(err)) {
const error = {
statusCode: 400,
error: 'Bad Request',
message: err.message,
validation: {
source: err._meta.source,
keys: []
}
};
const errors = () => (err, req, res, next) => {
if (isCelebrate(err)) {
const error = {
statusCode: 400,
error: 'Bad Request',
message: err.message,
validation: {
source: err._meta.source,
keys: [],
},
};
if (err.details) {
for (var i = 0; i < err.details.length; i++) {
/* istanbul ignore next */
const path = Array.isArray(err.details[i].path) ? err.details[i].path.join('.') : err.details[i].path;
error.validation.keys.push(EscapeHtml(path));
}
if (err.details) {
for (let i = 0; i < err.details.length; i += 1) {
const path = err.details[i].path.join('.');
error.validation.keys.push(EscapeHtml(path));
}
return res.status(400).send(error);
}
return res.status(400).send(error);
}
// If this isn't a Joi error, send it to the next error handler
return next(err);
};
// If this isn't a Celebrate error, send it to the next error handler
return next(err);
};

@@ -141,3 +137,3 @@

errors,
isCelebrate
isCelebrate,
};

@@ -1,3 +0,1 @@

'use strict';
const Joi = require('joi');

@@ -9,3 +7,3 @@

query: Joi.any(),
body: Joi.any()
body: Joi.any(),
}).min(1);
{
"name": "celebrate",
"version": "7.0.6",
"version": "8.0.0",
"description": "A joi validation middleware for Express.",

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

"scripts": {
"lint": "belly-button -i 'lib/*.js' -f",
"lint": "eslint lib test --fix",
"test": "npm run lint && jest --ci",

@@ -32,3 +32,3 @@ "benchmark": "node benchmarks/index"

"fastseries": "1.7.2",
"joi": "12.x.x"
"joi": "13.x.x"
},

@@ -39,12 +39,14 @@ "devDependencies": {

"artificial": "0.1.x",
"belly-button": "4.x.x",
"benchmark": "2.1.4",
"body-parser": "1.18.2",
"expect": "21.2.x",
"eslint": "4.19.x",
"eslint-config-airbnb-base": "12.1.x",
"eslint-plugin-import": "2.11.x",
"expect": "22.x.x",
"express": "5.0.0-alpha.6",
"jest": "21.2.x"
"jest": "22.x.x"
},
"engines": {
"node": ">=4.0.0"
"node": ">=8.9.0"
}
}

@@ -1,9 +0,23 @@

![Celebrate](https://github.com/continuationlabs/celebrate/raw/master/images/logo.png)
[![celebrate](https://github.com/arb/celebrate/raw/master/images/logo.svg?sanitize=1)](https://www.npmjs.org/package/celebrate)
<sub>Logo design by chris.ruppert@gmail.com</sub>
[![Current Version](https://img.shields.io/npm/v/celebrate.svg)](https://www.npmjs.org/package/celebrate)
[![Build Status](https://travis-ci.org/arb/celebrate.svg?branch=master)](https://travis-ci.org/arb/celebrate)
[![belly-button-style](https://img.shields.io/badge/eslint-bellybutton-4B32C3.svg)](https://github.com/continuationlabs/belly-button)
[![airbnb-style](https://img.shields.io/badge/eslint-airbnb-4B32C3.svg)](https://github.com/airbnb/javascript)
<table>
<tbody>
<tr>
<td>Sponsored by</td>
<td>
<a href="https://github.com/webflow/">
<img
height="100"
src="https://github.com/arb/celebrate/raw/master/images/webflow-logo-blue.svg?sanitize=1"
alt="Webflow"
/>
</a>
</td>
</tr>
</tbody>
</table>

@@ -10,0 +24,0 @@ `celebrate` is an express middleware function that wraps the [joi](https://github.com/hapijs/joi/tree/v12.0.0) validation library. This allows you to use this middleware in any single route, or globally, and ensure that all of your inputs are correct before any handler function. The middleware allows you to validate `req.params`, `req.headers`, `req.query` and `req.body` (provided you are using `body-parser`).

Sorry, the diff of this file is not supported yet

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