import-modules
Import all modules in a directory
Last updated 8 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ cnpm install import-modules 
SYNC missed versions from official npm registry.

import-modules Build Status

Import all modules in a directory

This module is intentionally simple. Not interested in more features.

Install

$ npm install import-modules

Usage

.
└── dir
    ├── foo-bar.js
    └── baz-faz.js
const importModules = require('import-modules');

const modules = importModules('directory');

console.log(modules);
//=> {fooBar: [Function], bazFaz: [Function]}

API

importModules(directory?, options?)

directory

Type: string
Default: __dirname

Directory to import modules from. Unless you've set the fileExtensions option, that means any .js, .json, .node files, in that order. Does not recurse. Ignores the caller file and files starting with . or _.

options

Type: object

camelize

Type: boolean
Default: true

Convert dash-style names (foo-bar) to camel-case (fooBar).

fileExtensions

Type: string[]
Default: ['.js', '.json', '.node']

File extensions to look for. Order matters.

Related

Current Tags

  • 2.0.0                                ...           latest (6 years ago)

2 Versions

  • 2.0.0                                ...           6 years ago
  • 1.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org