Socket
Socket
Sign inDemoInstall

needs

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

needs - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

25

lib/needs.js

@@ -63,2 +63,4 @@ 'use strict';

var filter = typeof options.filter === 'function' ? options.filter : defaultFilter;
var modules = {};

@@ -68,20 +70,9 @@ read(dir, options);

function defaultFilter(info) {
return require(info.file);
}
function register(modules, info) {
if (options['watch']) {
if (!info.stat) {
info.stat = fs.statSync(info.file);
}
modules.__defineGetter__(info.name, function() {
var stat = fs.statSync(info.file);
if (!info.cache || info.stat && info.stat.mtime < stat.mtime) {
debug('reload ' + info.file);
delete Module._cache[info.file];
info.cache = require(info.file);
}
info.stat = stat;
return info.cache;
});
} else {
modules[info.name] = require(info.file);
}
var m = filter(info);
if (!!m) modules[info.name] = m;
}

@@ -88,0 +79,0 @@

{
"name": "needs",
"version": "0.1.1",
"version": "0.1.2",
"description": "Require multiple modules in node.js.",

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

@@ -90,2 +90,22 @@ var chai = require('chai');

it('requiring modules with filter', function () {
var modules = needs(root, 'modules', {
module: true,
filter: function (info) {
var mod = require(info.file);
if (typeof mod === 'object') mod.moduleName = info.name;
return mod;
}
});
t.deepEqual(modules, {
foo: 'bar',
hello: {
world: true,
universe: 42,
moduleName: "hello"
}
});
});
});
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