1 | # rechoir [![Build Status](https://secure.travis-ci.org/tkellen/node-rechoir.png)](http://travis-ci.org/tkellen/node-rechoir)
|
2 | > Require any supported file as a node module.
|
3 |
|
4 | ## What is it?
|
5 | This module can find, require and register any file type the npm ecosystem has a module loader for.
|
6 |
|
7 | **Currently supported extensions:**
|
8 |
|
9 | `.co, .coco, .coffee, .iced, .ini, .js, .json, .litcoffee, .ls, .toml, .xml, .yaml, .yml`
|
10 |
|
11 | **Note:** If you'd like to add a new extension, please make a PR for [interpret](https://github.com/tkellen/node-interpret).
|
12 |
|
13 | ## API
|
14 |
|
15 | ### registerFor(filepath, requireFrom)
|
16 | Look for a module loader associated with the provided file and attempt require it. If necessary, run any setup required to inject it into [require.extensions](http://nodejs.org/api/globals.html#globals_require_extensions). If calling this method is successful (aka: it doesn't throw), you can now require files of the type you requested natively.
|
17 |
|
18 | `filepath` A file whose type you'd like to register a module loader for.
|
19 |
|
20 | `requireFrom` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`.
|
21 |
|
22 | **Note:** While rechoir will automatically load and register transpilers like `coffee-script`, you must provide a local installation. The transpilers are **not** bundled with this module..
|
23 |
|
24 | #### Usage
|
25 | ```js
|
26 | var rechoir = require('rechoir');
|
27 | rechoir.registerFor('path/to/file.coffee');
|
28 | // coffee-script is now loaded and registered with node
|
29 | require('file.coffee');
|
30 | ```
|
31 |
|
32 | ### load (filepath)
|
33 | Automatically call `requireFor`, then require the requested file and return the result.
|
34 |
|
35 | #### Usage
|
36 | ```js
|
37 | var rechoir = require('rechoir');
|
38 | rechoir.load('file.coffee');
|
39 | ```
|
40 |
|