Socket
Socket
Sign inDemoInstall

req-requires

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

req-requires - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

38

lib/req-requires.js

@@ -9,19 +9,39 @@ var requiredProperty = require('./requiredProperty');

//TODO: wrap this in a function that can receive a custom error handler
module.exports.error = function(err, req, res, next){
if(err === 'req-requires error')
res.send(400, req.requires.error);
else
next(err);
if(err === 'req-requires error')
module.exports.errorHandler(req.requires.error, req, res, next);
else
next(err);
}
module.exports.errorHandler = function(errorMessage, req, res, next){
res.send(400, errorMessage);
}
var requires = function(req, res, next){
this.property = function(name){
return new requiredProperty(req, name);
var self = this;
self.property = function(name){
return new requiredProperty(this, name);
}
this.fail = function(message){
this.error = message;
self.assertFail = function(message){
self.error = message;
throw('req-requires error');
}
self.getProperty = function(propertyName){
var currentValue=req;
var list=propertyName.split(".");
for (var i=0; i<list.length; i++)
{
currentValue=currentValue[list[i]];
if (typeof(currentValue)==='undefined')
return currentValue;
}
return currentValue;
}
return self;
}
var requiredProperty = function(requiresContext, propertyName){
this.context = requiresContext;
this.name = propertyName;
this.value = getPropertyValue(this.context,this.name);
this.value = this.context.getProperty(this.name);
return this;

@@ -10,18 +10,5 @@ }

if(!assertion())
this.context.fail('Expected '+this.name+' '+assertionText);
this.context.assertFail('Expected '+this.name+' '+assertionText);
}
function getPropertyValue(context, propertyName){
var currentValue=context;
var list=propertyName.split(".");
for (var i=0; i<list.length; i++)
{
currentValue=currentValue[list[i]];
if (typeof(currentValue)==='undefined')
return currentValue;
}
return currentValue;
}
module.exports = requiredProperty;
{
"name": "req-requires",
"version": "0.0.5",
"version": "0.0.6",
"description": "Add assertions to ExpressJS middleware",

@@ -5,0 +5,0 @@ "main": "./lib/req-requires.js",

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