# requireindex

> Write minimal node index.js files that require and export siblings by file basename

Latest version **1.2.0** (published 2018-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install requireindex
pnpm add requireindex
yarn add requireindex
bun add requireindex
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-02-10 |
| First published | 2012-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/requireindex) |
| Module format | CommonJS |
| Node | >=0.10.5 |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 84 |
| Author | Stephen Handley |
| Maintainers | stephenhandley |
| Keywords | require, index, index.js |

## Links

- npm: https://www.npmjs.com/package/requireindex
- Repository: https://github.com/stephenhandley/requireindex
- Issues: http://github.com/stephenhandley/requireindex/issues
- npm.io page: https://npm.io/package/requireindex

## Recent versions

- 1.2.0 (latest) — 2018-02-10
- 1.1.0 — 2014-01-17
- 1.0.1 — 2013-05-01
- 1.0.0 — 2012-09-26
- 0.1.8 — 2012-09-05
- 0.1.7 — 2012-06-05
- 0.1.6 — 2012-05-31
- 0.1.5 — 2012-05-30
- 0.1.4 — 2012-05-06
- 0.1.3 — 2012-05-04
- 0.1.2 — 2012-05-04
- 0.1.1 — 2012-05-04
- 0.1.0 — 2012-05-04
- 0.0.2 — 2012-05-01
- 0.0.1 — 2012-05-01

## README

# Description

Write minimal node index.js files that require and export siblings by file basename

# Latest Version

1.2.0

# Installation
```
npm install requireindex
```

or in package.json

```json
{
  ...
  "dependencies": {
    "requireindex": "1.1.x"
  }
}
```

# Usage
Check the [test directory](https://github.com/stephenhandley/requireindex/tree/master/test) for example usage. The [test/lib](https://github.com/stephenhandley/requireindex/tree/master/test/lib) looks like:

```
lib/
  index.js
  Foo.js
  bar/
    index.js
    f.js
    fing.js
    fed/
      again.js
      ignored.js
      index.js
      somemore.js
  bam.js
  _private.js

```

The index.js files in [test/lib/](https://github.com/stephenhandley/requireindex/tree/master/test/lib/index.js) and [test/lib/bar/](https://github.com/stephenhandley/requireindex/tree/master/test/lib/bar/index.js) contain:

```js
module.exports = require('requireindex')(__dirname);
```

and the index.js file in [test/lib/bar/fed/](https://github.com/stephenhandley/requireindex/tree/master/test/lib/bar/fed/index.js) contains:

```js
module.exports = require('requireindex')(__dirname, ['again', 'somemore']);
```

The optional second argument allows you to explicitly specify the required files using their basename. In this example [test/lib/bar/fed/ignored.js](https://github.com/stephenhandley/requireindex/tree/master/test/lib/bar/fed/ignored.js) is not included as a public module. The other way to make a module/file private without the need for explicitly naming all the other included files is to prefix the filename with an underscore, as demonstrated by [test/lib/_private.js](https://github.com/stephenhandley/requireindex/tree/master/test/lib/_private.js) which is not exported.

So, with these index.js files, the result of

```js
require('lib');
```

is:

```js
{
  bam: {
    m: [Function],
    n: [Function]
  },
  bar: {
    f: [Function],
    fed: {
      again: [Function],
      somemore: [Function]
    },
    fing: [Function]
  },
  Foo: {
    l: [Function],
    ls: [Function]
  }
}
```

#Build status
[![build status](https://secure.travis-ci.org/stephenhandley/requireindex.png)](http://travis-ci.org/stephenhandley/requireindex)

---
_Source: https://npm.io/package/requireindex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
