You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. [![NPM](https://nodei.co/npm/rechoir.png)](https://nodei.co/npm/rechoir/)
  4. ## What is it?
  5. 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].
  6. ## API
  7. ### prepare(config, filepath, requireFrom)
  8. 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).
  9. `config` An [interpret]-like configuration object.
  10. `filepath` A file whose type you'd like to register a module loader for.
  11. `requireFrom` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`.
  12. If calling this method is successful (aka: it doesn't throw), you can now require files of the type you requested natively.
  13. An error with a `failures` property will be thrown if the module loader(s) configured for a given extension cannot be registered.
  14. If a loader is already registered, this will simply return `true`.
  15. **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.
  16. #### Usage
  17. ```js
  18. const config = require('interpret').extensions;
  19. const rechoir = require('rechoir');
  20. rechoir.prepare(config, './test/fixtures/test.coffee');
  21. rechoir.prepare(config, './test/fixtures/test.csv');
  22. rechoir.prepare(config, './test/fixtures/test.toml');
  23. console.log(require('./test/fixtures/test.coffee'));
  24. console.log(require('./test/fixtures/test.csv'));
  25. console.log(require('./test/fixtures/test.toml'));
  26. ```
  27. [interpret]: http://github.com/tkellen/js-interpret
  28. [Liftoff]: http://github.com/tkellen/js-liftoff