Comparing version 1.0.3 to 1.0.4
@@ -10,2 +10,6 @@ Change Log | ||
* npm package version updated to 1.0.3 | ||
* Modified package config to use `keywords` instead of `tags` | ||
* Modified package config to use `keywords` instead of `tags` | ||
## 2012-07-03 ## | ||
* npm package version updated to 1.0.4 | ||
* Fixed the closure in requiredir.js that somehow got messed up. Private members no longer leak. |
{ | ||
"name": "requiredir", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "James Eggers <james.r.eggers@gmail.com> (http://www.jamesreggers.com/)", | ||
@@ -5,0 +5,0 @@ "description": "A module for importing a directory of Node.js modules and adding them into an array or as properties of the module variable.", |
@@ -5,64 +5,56 @@ "use strict"; | ||
module.exports = function(path){ | ||
_verifyDirectory(path); | ||
var fileList = [] | ||
, modules = []; | ||
var files = _fs.readdirSync(path); | ||
return _importFiles(path, files); | ||
}; | ||
module.exports = (function(){ | ||
var _verifyDirectory = function(path) { | ||
var stats; | ||
if (typeof path === "undefined" | ||
|| (typeof path === "string" && path.trim().length === 0)) { | ||
throw new TypeError("The path must be provided when instantiating the object."); | ||
} | ||
try { | ||
stats = _fs.statSync(path); | ||
} catch (e) { | ||
throw new TypeError("The directory path does not exist."); | ||
} | ||
if (!stats.isDirectory()){ | ||
throw new TypeError("The path provided is not a directory."); | ||
} | ||
}; | ||
var _verifyDirectory = function(path) { | ||
var stats; | ||
var _importFiles = function(path, files){ | ||
var moduleList = [] | ||
, relativePath = _path.resolve(process.cwd() + "/" + path) | ||
, trimmedName | ||
, module | ||
, obj = {}; | ||
files.forEach(function (element, index, array){ | ||
if (_fs.lstatSync(path + "/" + element).isFile() && element.substring(0,1) !== "."){ | ||
trimmedName = element.substring(0, (element.length - 3)); | ||
module = require(relativePath + "/" + trimmedName); | ||
moduleList.push(module); | ||
obj[trimmedName] = module; | ||
if (typeof path === "undefined" | ||
|| (typeof path === "string" && path.trim().length === 0)) { | ||
throw new TypeError("The path must be provided when instantiating the object."); | ||
} | ||
}); | ||
try { | ||
stats = _fs.statSync(path); | ||
} catch (e) { | ||
throw new TypeError("The directory path does not exist."); | ||
} | ||
if (!stats.isDirectory()){ | ||
throw new TypeError("The path provided is not a directory."); | ||
} | ||
}; | ||
var _importFiles = function(path, files){ | ||
var moduleList = [] | ||
, relativePath = _path.resolve(process.cwd() + "/" + path) | ||
, trimmedName | ||
, module | ||
, obj = {}; | ||
files.forEach(function (element, index, array){ | ||
if (_fs.lstatSync(path + "/" + element).isFile() && element.substring(0,1) !== "."){ | ||
trimmedName = element.substring(0, (element.length - 3)); | ||
module = require(relativePath + "/" + trimmedName); | ||
moduleList.push(module); | ||
obj[trimmedName] = module; | ||
} | ||
}); | ||
obj.length = moduleList.length; | ||
obj.toArray = function(){return moduleList;}; | ||
return obj; | ||
}; | ||
obj.length = moduleList.length; | ||
obj.toArray = function(){return moduleList;}; | ||
return obj; | ||
}; | ||
return function(path){ | ||
_verifyDirectory(path); | ||
(function(){ | ||
var fileList = [] | ||
, modules = []; | ||
var files = _fs.readdirSync(path); | ||
return _importFiles(path, files); | ||
}; | ||
}()); |
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
9306