Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conire - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

@@ -6,3 +6,3 @@ 'use strict';

* return required module based on key
* @param {string} key key used for lookup
* @param {string} key key used for lookup. if falsy fallback is returned
* @param {object} modules contains options to be required.

@@ -19,3 +19,3 @@ * key is lookup key, value is module to be required

// if key is in modules, return required
if (modules[key]) {
if (key && modules[key]) {
var item = modules[key];

@@ -27,3 +27,3 @@ item = patchIfPath(modules[key]);

// key not found, return fallback
// key not found or is false, return fallback
return getFallback(fallback);

@@ -39,4 +39,5 @@ };

function validate (key, modules) {
if (typeof key !== 'string' || key.length <= 0) {
throw new Error('key should be a non-empty string');
// if key exist, it must be a string
if (key && typeof key !== 'string') {
throw new Error('key should be a string');
}

@@ -43,0 +44,0 @@

{
"name": "conire",
"version": "1.0.2",
"version": "1.0.3",
"description": "conditional require of modules",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,2 +8,4 @@ # conire

// key used to find which module to require
// if key is falsy, fallback will be set
// if key is not falsy, it must be a string
var key = process.env.NODE_ENV;

@@ -10,0 +12,0 @@

@@ -78,7 +78,16 @@ 'use strict';

});
[null, undefined, '', false].forEach(function(testKey) {
it('should should return fallback if key is falsy: '+testKey, function(done) {
var test = conair(testKey, {}, 123456);
expect(test).to.equal(123456);
done();
});
});
});
describe('incorrect usage', function () {
[{}, [], null, undefined, {a:1}, '', false, true].forEach(function(testKey) {
it('should error if invalid key '+testKey, function(done) {
[{}, [], {a:1}, true].forEach(function(testKey) {
it('should error if invalid key: '+testKey, function(done) {
try {

@@ -93,3 +102,3 @@ conair(testKey, {});

[[], null, undefined, '', false, true, 'fake'].forEach(function(testModule) {
it('should error if invalid modulelist '+testModule, function(done) {
it('should error if invalid modulelist: '+testModule, function(done) {
try {

@@ -96,0 +105,0 @@ conair('test', testModule);