2222` requireDir('./dir') ` will return the equivalent of:
2323
2424``` js
25- { a: require (' ./dir/a.js' )
26- , b: require (' ./dir/b.json' )
25+ {
26+ a: require (' ./dir/a.js' ),
27+ b: require (' ./dir/b.json' )
2728}
2829```
2930
30- And if CoffeeScript has been registered via ` require('coffee-script/register') ` ,
31+ If CoffeeScript is registered via ` require('coffee-script/register') ` ,
3132` c.coffee ` will also be returned. Any extension registered with node will work the same way without any additional configuration.
3233
3334## Installation
@@ -51,7 +52,7 @@ var dir = requireDir('./path/to/dir');
5152You can optionally customize the behavior by passing an extra options object:
5253
5354``` js
54- var dir = requireDir (' ./path/to/dir' , {recurse: true });
55+ var dir = requireDir (' ./path/to/dir' , { recurse: true });
5556```
5657
5758## Options
@@ -60,25 +61,6 @@ var dir = requireDir('./path/to/dir', {recurse: true});
6061(` node_modules ` within subdirectories will be ignored.)
6162Default is false.
6263
63- ` duplicates ` : By default, if multiple files share the same basename, only the
64- highest priority one is ` require() ` 'd and returned. (Priority is determined by
65- the order of ` require.extensions ` keys, with directories taking precedence
66- over files if ` recurse ` is true.) Specifying this option ` require() ` 's all
67- files and returns full filename keys in addition to basename keys.
68- Default is false.
69-
70- E.g. in the example above, if there were also an ` a.json ` , the behavior would
71- be the same by default, but specifying ` duplicates: true ` would yield:
72-
73- ``` js
74- { a: require (' ./dir/a.js' )
75- , ' a.js' : require (' ./dir/a.js' )
76- , ' a.json' : require (' ./dir/a.json' )
77- , b: require (' ./dir/b.json' )
78- , ' b.json' : require (' ./dir/b.json' )
79- }
80- ```
81-
8264` filter ` : Apply a filter on the filename before require-ing. For example, ignoring files prefixed with ` dev ` in a production environment:
8365
8466``` js
@@ -109,10 +91,29 @@ requireDir('./dir', {
10991})
11092```
11193
94+ ` duplicates ` : By default, if multiple files share the same basename, only the
95+ highest priority one is ` require() ` 'd and returned. (Priority is determined by
96+ the order of ` require.extensions ` keys, with directories taking precedence
97+ over files if ` recurse ` is true.) Specifying this option ` require() ` 's all
98+ files and returns full filename keys in addition to basename keys.
99+ Default is false.
100+
101+ In the example above, if there were also an ` a.json ` , the behavior would
102+ be the same by default, but specifying ` duplicates: true ` would yield:
103+
104+ ``` js
105+ {
106+ a: require (' ./dir/a.js' ),
107+ ' a.js' : require (' ./dir/a.js' ),
108+ ' a.json' : require (' ./dir/a.json' ),
109+ b: require (' ./dir/b.json' ),
110+ ' b.json' : require (' ./dir/b.json' )
111+ }
112+ ```
113+
112114## Tips
113115
114- If you want to ` require() ` the same directory in multiple places, you can do
115- this in the directory itself! Just make an ` index.js ` file with the following:
116+ Make an ` index.js ` in a directory with this code to clean things up:
116117
117118``` js
118119module .exports = require (' require-dir' )(); // defaults to '.'
0 commit comments