Comparing version 1.0.1 to 1.1.0
64
index.js
@@ -1,16 +0,30 @@ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
camelcase = require('camelcase'); | ||
var fs = require('fs') | ||
var path = require('path') | ||
var camelcase = require('camelcase') | ||
var pascalcase = require('uppercamelcase') | ||
var exports = module.exports = function(dir, options) { | ||
var modules = {}; | ||
options = options || {}; | ||
module.exports = load | ||
function load(dir, options) { | ||
var modules = {} | ||
options = options || {} | ||
if (typeof options === 'function') { | ||
options = {init: options}; | ||
} else { | ||
options = merge(options, { | ||
lazy: true, | ||
init: function(mod){ return mod; } | ||
}); | ||
options = {init: options} | ||
} | ||
switch (options.naming) { | ||
case 'camel': | ||
options.naming = camelcase | ||
break | ||
case 'pascal': | ||
options.naming = pascalcase | ||
break | ||
default: | ||
options.naming = identify | ||
break | ||
} | ||
options = merge(options, { | ||
lazy: true, | ||
init: identify, | ||
}) | ||
@@ -20,5 +34,5 @@ fs.readdirSync(dir).forEach(function(filename) { | ||
if (filename !== 'index.js' && filename[0] !== '.') { | ||
var moduleName = path.basename(filename, path.extname(filename)); | ||
var modulePath = path.join(dir, moduleName); | ||
var exportName = camelcase(moduleName); | ||
var moduleName = path.basename(filename, path.extname(filename)) | ||
var modulePath = path.join(dir, moduleName) | ||
var exportName = options.naming(moduleName) | ||
// lazy load | ||
@@ -28,13 +42,13 @@ if (options.lazy) { | ||
get: function() { | ||
return options.init(require(modulePath)); | ||
return options.init(require(modulePath)) | ||
} | ||
}); | ||
}) | ||
} else { | ||
modules[exportName] = options.init(require(modulePath)); | ||
modules[exportName] = options.init(require(modulePath)) | ||
} | ||
} | ||
}); | ||
}) | ||
return modules; | ||
}; | ||
return modules | ||
} | ||
@@ -44,6 +58,10 @@ function merge(obj, src) { | ||
if (src.hasOwnProperty(key) && obj[key] === undefined) { | ||
obj[key] = src[key]; | ||
obj[key] = src[key] | ||
} | ||
} | ||
return obj; | ||
return obj | ||
} | ||
function identify(value) { | ||
return value | ||
} |
{ | ||
"name": "moder", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Module loader", | ||
@@ -12,3 +12,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"camelcase": "^2.1.1" | ||
"camelcase": "^2.1.1", | ||
"uppercamelcase": "^1.1.0" | ||
}, | ||
@@ -15,0 +16,0 @@ "main": "index.js", |
@@ -48,3 +48,3 @@ var path = require('path'), | ||
it('should convert module name to camel case', function() { | ||
var case6 = moder(__dirname + '/modules/case6'); | ||
var case6 = moder(__dirname + '/modules/case6', {naming: 'camel'}); | ||
assert.deepEqual(case6.fooBar, 'hello world'); | ||
@@ -54,5 +54,10 @@ }); | ||
it('should convert module name to camel case without lazy evaluation', function() { | ||
var case7 = moder(__dirname + '/modules/case7', {lazy: false}); | ||
var case7 = moder(__dirname + '/modules/case7', {lazy: false, naming: 'camel'}); | ||
assert.deepEqual(case7.fooBar, 'hello world'); | ||
}); | ||
it('should convert module name to pascal case', function() { | ||
var case6 = moder(__dirname + '/modules/case7', {naming: 'pascal'}); | ||
assert.deepEqual(case6.FooBar, 'hello world'); | ||
}); | ||
}); |
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
7454
27
124
2
+ Addeduppercamelcase@^1.1.0
+ Addedcamelcase@1.2.1(transitive)
+ Addeduppercamelcase@1.1.0(transitive)