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

require-all

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-all - npm Package Compare versions

Comparing version 0.0.6 to 0.0.8

21

index.js

@@ -1,5 +0,13 @@

var fs = require('fs');
var fs = require('fs');
module.exports = function requireAll(options) {
var files = fs.readdirSync(options.dirname);
if (typeof options === 'string') {
options = {
dirname: options,
filter: /(.+)\.js(on)?$/,
excludeDirs: /^\.(git|svn)$/
};
}
var files = fs.readdirSync(options.dirname);
var modules = {};

@@ -11,3 +19,3 @@

files.forEach(function(file) {
files.forEach(function (file) {
var filepath = options.dirname + '/' + file;

@@ -19,5 +27,5 @@ if (fs.statSync(filepath).isDirectory()) {

modules[file] = requireAll({
dirname : filepath,
filter : options.filter,
excludeDirs : options.excludeDirs
dirname: filepath,
filter: options.filter,
excludeDirs: options.excludeDirs
});

@@ -35,2 +43,1 @@

};

@@ -5,3 +5,3 @@ {

"description": "An easy way to require all files within a directory.",
"version": "0.0.6",
"version": "0.0.8",
"scripts": {

@@ -25,4 +25,6 @@ "test": "node test/test.js"

"dependencies": {},
"devDependencies": {},
"devDependencies": {
"semver": "~2.1.0"
},
"optionalDependencies": {}
}

@@ -18,1 +18,9 @@ # require-all

```
## Advanced usage
If your objective is to simply require all .js and .json files in a directory you can just pass a string to require-all:
``` js
var libs = require('require-all')(__dirname + '/lib');
```
var assert = require('assert');
var semver = require('semver');
var requireAll = require('..');

@@ -23,4 +24,6 @@

if (process.version > 'v0.6.0') {
//
// requiring json only became an option in 0.6+
//
if (semver.gt(process.version, 'v0.6.0')) {
var mydir = requireAll({

@@ -31,10 +34,22 @@ dirname: __dirname + '/mydir',

assert.deepEqual(mydir, {
var mydir_contents = {
foo: 'bar',
hello: { world: true, universe: 42 },
hello: {
world: true,
universe: 42
},
sub: {
config: { settingA: 'A', settingB: 'B' },
config: {
settingA: 'A',
settingB: 'B'
},
yes: true
}
});
};
assert.deepEqual(mydir, mydir_contents);
var defaults = requireAll(__dirname + '/mydir');
assert.deepEqual(defaults, mydir_contents);
}

@@ -48,4 +63,4 @@

assert(unfiltered['.svn']);
assert(unfiltered['root']);
assert(unfiltered['sub']);
assert(unfiltered.root);
assert(unfiltered.sub);

@@ -59,4 +74,4 @@ var excludedSvn = requireAll({

assert.equal(excludedSvn['.svn'], undefined);
assert.ok(excludedSvn['root']);
assert.ok(excludedSvn['sub']);
assert.ok(excludedSvn.root);
assert.ok(excludedSvn.sub);

@@ -70,3 +85,3 @@ var excludedSvnAndSub = requireAll({

assert.equal(excludedSvnAndSub['.svn'], undefined);
assert.ok(excludedSvnAndSub['root']);
assert.equal(excludedSvnAndSub['sub'], undefined);
assert.ok(excludedSvnAndSub.root);
assert.equal(excludedSvnAndSub.sub, undefined);

Sorry, the diff of this file is not supported yet

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