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.5 to 0.1.6

50

lib/needs.js
'use strict';
// Nodejs libs.
var fs = require('fs');

@@ -8,2 +7,3 @@ var path = require('path');

var existsSync = fs.existsSync || path.existsSync;
var slice = Array.prototype.slice;

@@ -16,3 +16,3 @@ // The module to be exported.

var matchPatterns = function(patterns, fn) {
function matchPatterns(patterns, fn) {
var result = false;

@@ -31,5 +31,5 @@ // Iterate over flattened patterns array.

return result;
};
}
var match = function (filename, patterns, options) {
function match(filename, patterns, options) {
options = _.assign({

@@ -48,23 +48,37 @@ matchBase: true

});
}
};
function join(args) {
if (args.length === 1) {
return args[0];
} else if (args.length === 2) {
return path.join(args[0], args[1])
} else if (args.length === 3) {
return path.join(args[0], args[1], args[2])
} else if (args.length === 4) {
return path.join(args[0], args[1], args[2], args[3])
} else {
return path.join.apply(path, args);
}
}
function needs(root, name, options) {
var dir = root;
if (typeof name === 'string') {
dir = path.join(root, name);
} else if (name) {
options = name;
function needs() {
if (arguments.length == 0 || typeof arguments[0] !== 'string') throw new Error('`dir` must be a string');
var dir, opts = {};
var args = slice.call(arguments);
var len = args.length;
if (typeof args[len - 1] === 'object') {
opts = args.pop();
}
options = _.assign({
prefix: '',
patterns: '+(*.js|*.json)',
excludes: '+(*.git|*.svn)'
}, options);
dir = join(args);
opts.prefix = opts.prefix || '';
opts.patterns = opts.patterns || opts.includes || opts.include || '+(*.js|*.json)';
opts.excludes = opts.excludes || opts.exclude || '+(*.git|*.svn)';
var filter = typeof options.filter === 'function' ? options.filter : defaultFilter;
var filter = typeof opts.filter === 'function' ? opts.filter : defaultFilter;
var modules = {};
read(dir, options);
read(dir, opts);
return modules;

@@ -71,0 +85,0 @@

{
"name": "needs",
"version": "0.1.5",
"version": "0.1.6",
"description": "Require multiple modules in node.js.",

@@ -27,9 +27,9 @@ "main": "index.js",

"devDependencies": {
"chai": "~1.9.0",
"mocha": "~1.17.1"
"chai": "~1.9.1",
"mocha": "~1.21.4"
},
"dependencies": {
"lodash": "~2.4.1",
"minimatch": "~0.2.14"
"minimatch": "~1.0.0"
}
}

@@ -1,5 +0,15 @@

#needs
Needs
=====
[![NPM Version](https://img.shields.io/npm/v/needs.svg?style=flat)](https://www.npmjs.org/package/needs)
[![Build Status](http://img.shields.io/travis/taoyuan/needs.svg?style=flat)](https://travis-ci.org/taoyuan/needs)
[![Dependencies](https://img.shields.io/david/taoyuan/needs.svg?style=flat)](https://david-dm.org/taoyuan/needs)
Require multiple modules in node.js.
## Installation
```bash
$ npm install yetta
```
##Usage

@@ -9,3 +19,3 @@

var controllers = require('needs')(__dirname, 'controllers', {
filter: /(.+Controller)\.js$/,
includes: /(.+Controller)\.js$/,
excludes: /^\.(git|svn)$/

@@ -27,5 +37,9 @@ });

##Reference Projects
##Links
* [node-require-all](http://github.com/felixge/node-require-all)
* [compound.js](http://github.com/1602/compound)
## License
Copyright (c) 2014 Tao Yuan
Licensed under the MIT license.

@@ -11,3 +11,3 @@ var chai = require('chai');

var controllers = needs(root, 'controllers', {
patterns: '*Controller.js'
includes: '*Controller.js'
});

@@ -31,3 +31,3 @@ t.deepEqual(controllers, {

var mydir = needs(root, 'mydir', {
patterns: '+(*.js|*.json)'
includes: '+(*.js|*.json)'
});

@@ -56,3 +56,3 @@

var unfiltered = needs(root, 'filterdir', {
patterns: '*.js'
includes: '*.js'
});

@@ -64,3 +64,3 @@

var excludedSub = needs(root, 'filterdir', {
patterns: '*.js',
includes: '*.js',
excludes: 'sub'

@@ -67,0 +67,0 @@ });

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