UNPKG

1.8 kBMarkdownView Raw
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[![NPM](https://nodei.co/npm/rechoir.png)](https://nodei.co/npm/rechoir/)
5
6
7## What is it?
8This module can find, require and register any file type the npm ecosystem has a module loader for.
9
10**Currently supported extensions:**
11
12`.co, .coco, .coffee, .iced, .ini, .js, .json, .litcoffee, .ls, .toml, .xml, .yaml, .yml`
13
14**Note:** If you'd like to add a new extension, please make a PR for [interpret](https://github.com/tkellen/node-interpret).
15
16## API
17
18### registerFor(filepath, requireFrom)
19Look 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.
20
21`filepath` A file whose type you'd like to register a module loader for.
22
23`requireFrom` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`.
24
25**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..
26
27#### Usage
28```js
29var rechoir = require('rechoir');
30rechoir.registerFor('path/to/file.coffee');
31// coffee-script is now loaded and registered with node
32require('file.coffee');
33```
34
35### load (filepath)
36Automatically call `requireFor`, then require the requested file and return the result.
37
38#### Usage
39```js
40var rechoir = require('rechoir');
41rechoir.load('file.coffee');
42```
43