Skip to content

Commit

Permalink
doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Feb 7, 2018
1 parent 015fb1b commit 1edb135
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ dir
`requireDir('./dir')` will return the equivalent of:

```js
{ a: require('./dir/a.js')
, b: require('./dir/b.json')
{
a: require('./dir/a.js'),
b: require('./dir/b.json')
}
```

And if CoffeeScript has been registered via `require('coffee-script/register')`,
If CoffeeScript is registered via `require('coffee-script/register')`,
`c.coffee` will also be returned. Any extension registered with node will work the same way without any additional configuration.

## Installation
Expand All @@ -51,7 +52,7 @@ var dir = requireDir('./path/to/dir');
You can optionally customize the behavior by passing an extra options object:

```js
var dir = requireDir('./path/to/dir', {recurse: true});
var dir = requireDir('./path/to/dir', { recurse: true });
```

## Options
Expand All @@ -60,25 +61,6 @@ var dir = requireDir('./path/to/dir', {recurse: true});
(`node_modules` within subdirectories will be ignored.)
Default is false.

`duplicates`: By default, if multiple files share the same basename, only the
highest priority one is `require()`'d and returned. (Priority is determined by
the order of `require.extensions` keys, with directories taking precedence
over files if `recurse` is true.) Specifying this option `require()`'s all
files and returns full filename keys in addition to basename keys.
Default is false.

E.g. in the example above, if there were also an `a.json`, the behavior would
be the same by default, but specifying `duplicates: true` would yield:

```js
{ a: require('./dir/a.js')
, 'a.js': require('./dir/a.js')
, 'a.json': require('./dir/a.json')
, b: require('./dir/b.json')
, 'b.json': require('./dir/b.json')
}
```

`filter`: Apply a filter on the filename before require-ing. For example, ignoring files prefixed with `dev` in a production environment:

```js
Expand Down Expand Up @@ -109,10 +91,29 @@ requireDir('./dir', {
})
```

`duplicates`: By default, if multiple files share the same basename, only the
highest priority one is `require()`'d and returned. (Priority is determined by
the order of `require.extensions` keys, with directories taking precedence
over files if `recurse` is true.) Specifying this option `require()`'s all
files and returns full filename keys in addition to basename keys.
Default is false.

In the example above, if there were also an `a.json`, the behavior would
be the same by default, but specifying `duplicates: true` would yield:

```js
{
a: require('./dir/a.js'),
'a.js': require('./dir/a.js'),
'a.json': require('./dir/a.json'),
b: require('./dir/b.json'),
'b.json': require('./dir/b.json')
}
```

## Tips

If you want to `require()` the same directory in multiple places, you can do
this in the directory itself! Just make an `index.js` file with the following:
Make an `index.js` in a directory with this code to clean things up:

```js
module.exports = require('require-dir')(); // defaults to '.'
Expand Down

0 comments on commit 1edb135

Please sign in to comment.