grailed-module-adapter
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "grailed-module-adapter", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -1,41 +0,41 @@ | ||
module.exports = function(_module) { | ||
var _ = require('underscore'), | ||
is = require('sc-is'), | ||
module = _module, | ||
express = require('express'), | ||
path = require('path'), | ||
fs = require('fs'), | ||
routes, | ||
router = express.Router(); | ||
module.exports = function ( _module ) { | ||
var _ = require( 'underscore' ), | ||
is = require( 'sc-is' ), | ||
module = _module, | ||
express = require( 'express' ), | ||
path = require( 'path' ), | ||
fs = require( 'fs' ), | ||
routes, | ||
router = express.Router(); | ||
var dir = path.join(module.options.dirname, '../routes.js'); | ||
if (fs.existsSync(dir)) { | ||
routes = require(dir)(module); | ||
} | ||
var dir = path.join( module.options.dirname, '../routes.js' ); | ||
if ( fs.existsSync( dir ) ) { | ||
routes = require( dir )( module ); | ||
} | ||
if (routes && !Array.isArray(routes)) throw new Error('The routes for the module ' + module.name + ' is not a valid Array.'); | ||
if ( routes && !Array.isArray( routes ) ) throw new Error( 'The routes for the module ' + module.name + ' is not a valid Array.' ); | ||
if (routes) { | ||
routes.forEach(function(_route) { | ||
Object.keys(_route).forEach(function(_verb) { | ||
var route = _route[_verb], | ||
errorString = 'The route `' + _verb.toUpperCase() + ' ' + _route.path + '` for the module `' + module.name + '` was not an Array or Function'; | ||
if ( routes ) { | ||
routes.forEach( function ( _route ) { | ||
Object.keys( _route ).forEach( function ( _verb ) { | ||
var route = _route[ _verb ], | ||
errorString = 'The route `' + _verb.toUpperCase() + ' ' + _route.path + '` for the module `' + module.name + '` was not an Array or Function'; | ||
if (_verb === 'path') return; | ||
if ( _verb === 'path' ) return; | ||
if (is.not.an.array(route) && is.not.a.func(route)) | ||
throw new Error(errorString); | ||
if ( is.not.an.array( route ) && is.not.a.func( route ) ) | ||
throw new Error( errorString ); | ||
if (is.an.array(route)) { | ||
_.each(route, function(_middleware) { | ||
if (is.not.a.func(_middleware)) throw new Error(errorString); | ||
}); | ||
} | ||
if ( is.an.array( route ) ) { | ||
_.each( route, function ( _middleware ) { | ||
if ( is.not.an.array( _middleware ) && is.not.a.func( _middleware ) ) throw new Error( errorString ); | ||
} ); | ||
} | ||
router[_verb](_route.path, route); | ||
}); | ||
}); | ||
} | ||
router[ _verb ]( _route.path, route ); | ||
} ); | ||
} ); | ||
} | ||
return router; | ||
return router; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3344
0