Socket
Socket
Sign inDemoInstall

moder

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

moder - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

test/modules/case8/foo-bar.js

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');
});
});
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