UNPKG

2.77 kBMarkdownView Raw
1# interpret
2> A dictionary of file extensions and associated module loaders.
3
4[![NPM](https://nodei.co/npm/interpret.png)](https://nodei.co/npm/interpret/)
5
6## What is it
7This is used by [Liftoff](http://github.com/tkellen/node-liftoff) to automatically require dependencies for configuration files, and by [rechoir](http://github.com/tkellen/node-rechoir) for registering module loaders.
8
9## API
10
11### extensions
12Map file types to modules which provide a [require.extensions] loader.
13
14```js
15{
16 '.babel.js': {
17 module: 'babel/register',
18 register: function (module) {
19 module({
20 // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
21 // which only captures the final extension (.babel.js -> .js)
22 extensions: '.js'
23 })
24 }
25 },
26 '.cirru': 'cirru-script/lib/register',
27 '.cjsx': 'node-cjsx/register',
28 '.co': 'coco',
29 '.coffee': ['coffee-script/register', 'coffee-script'],
30 '.coffee.md': ['coffee-script/register', 'coffee-script'],
31 '.csv': 'require-csv',
32 '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
33 '.iced.md': ['iced-coffee-script/register', 'iced-coffee-script'],
34 '.ini': 'require-ini',
35 '.js': null,
36 '.json': null,
37 '.json5': 'json5/lib/require',
38 '.jsx': [
39 {
40 module: 'babel/register',
41 function (module) {
42 module({
43 extensions: '.jsx'
44 });
45 },
46 },
47 {
48 module: 'node-jsx',
49 register: function (module) {
50 module.install({
51 extension: '.jsx',
52 harmony: true
53 });
54 }
55 }
56 ],
57 '.litcoffee': ['coffee-script/register', 'coffee-script'],
58 '.liticed': ['iced-coffee-script/register', 'iced-coffee-script'],
59 '.ls': ['livescript', 'LiveScript'],
60 '.node': null,
61 '.toml': 'toml-require',
62 '.ts': ['typescript-register', 'typescript-require'],
63 '.wisp': 'wisp/engine/node',
64 '.xml': 'require-xml',
65 '.yaml': 'require-yaml',
66 '.yml': 'require-yaml'
67};
68```
69
70### jsVariants
71Same as above, but only include the extensions which are javascript variants.
72
73## How to use it
74
75Consumers should use the exported `extensions` or `jsVariants` object to determine which module should be loaded for a given extension. If a matching extension is found, consumers should do the following:
76
771. If the value is null, do nothing.
78
792. If the value is a string, try to require it.
80
813. If the value is an object, try to require the `module` property. If successful, the `register` property (a function) should be called with the module passed as the first argument.
82
834. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
84
85[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions