Initial commit
[yaffs-website] / node_modules / rechoir / README.md
1 # rechoir [![Build Status](https://secure.travis-ci.org/tkellen/js-rechoir.png)](http://travis-ci.org/tkellen/js-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 ## What is it?
7 This module, in conjunction with [interpret]-like objects can register any file type the npm ecosystem has a module loader for. This library is a dependency of [Liftoff].
8
9 ## API
10
11 ### prepare(config, filepath, requireFrom)
12 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).
13
14 `config` An [interpret]-like configuration object.  
15
16 `filepath` A file whose type you'd like to register a module loader for.
17
18 `requireFrom` An optional path to start searching for the module required to load the requested file.  Defaults to the directory of `filepath`.
19
20 If calling this method is successful (aka: it doesn't throw), you can now require files of the type you requested natively.
21
22 An error with a `failures` property will be thrown if the module loader(s) configured for a given extension cannot be registered.
23
24 If a loader is already registered, this will simply return `true`.
25
26 **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.
27
28 #### Usage
29 ```js
30 const config = require('interpret').extensions;
31 const rechoir = require('rechoir');
32 rechoir.prepare(config, './test/fixtures/test.coffee');
33 rechoir.prepare(config, './test/fixtures/test.csv');
34 rechoir.prepare(config, './test/fixtures/test.toml');
35
36 console.log(require('./test/fixtures/test.coffee'));
37 console.log(require('./test/fixtures/test.csv'));
38 console.log(require('./test/fixtures/test.toml'));
39 ```
40
41 [interpret]: http://github.com/tkellen/js-interpret
42 [Liftoff]: http://github.com/tkellen/js-liftoff