Initial commit
[yaffs-website] / node_modules / interpret / README.md
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
7 This 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
12 Map file types to modules which provide a [require.extensions] loader.
13
14 ```js
15 {
16   '.babel.js': [
17     {
18       module: 'babel-register',
19       register: function (module) {
20         module({
21           // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
22           // which only captures the final extension (.babel.js -> .js)
23           extensions: '.js'
24         });
25       }
26     },
27     {
28       module: 'babel-core/register',
29       register: function (module) {
30         module({
31           extensions: '.js'
32         });
33       }
34     },
35     {
36       module: 'babel/register',
37       register: function (module) {
38         module({
39           extensions: '.js'
40         });
41       }
42     }
43   ],
44   '.buble.js': [
45     {
46       module: 'buble/register',
47       register: function (module) {
48         module({
49           extensions: '.js'
50         });
51       }
52     }
53   ],
54   '.cirru': 'cirru-script/lib/register',
55   '.cjsx': 'node-cjsx/register',
56   '.co': 'coco',
57   '.coffee': ['coffee-script/register', 'coffee-script'],
58   '.coffee.md': ['coffee-script/register', 'coffee-script'],
59   '.csv': 'require-csv',
60   '.eg': 'earlgrey/register',
61   '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
62   '.iced.md': 'iced-coffee-script/register',
63   '.ini': 'require-ini',
64   '.js': null,
65   '.json': null,
66   '.json5': 'json5/lib/require',
67   '.jsx': [
68     {
69       module: 'babel-register',
70       register: function (module) {
71         module({
72           extensions: '.jsx'
73         });
74       }
75     },
76     {
77       module: 'babel-core/register',
78       register: function (module) {
79         module({
80           extensions: '.jsx'
81         });
82       }
83     },
84     {
85       module: 'babel/register',
86       register: function (module) {
87         module({
88           extensions: '.jsx'
89         });
90       },
91     },
92     {
93       module: 'node-jsx',
94       register: function (module) {
95         module.install({
96           extension: '.jsx',
97           harmony: true
98         });
99       }
100     }
101   ],
102   '.litcoffee': ['coffee-script/register', 'coffee-script'],
103   '.liticed': 'iced-coffee-script/register',
104   '.ls': ['livescript', 'LiveScript'],
105   '.node': null,
106   '.toml': {
107     module: 'toml-require',
108     register: function (module) {
109       module.install();
110     }
111   },
112   '.ts': ['ts-node/register', 'typescript-node/register', 'typescript-register', 'typescript-require'],
113   '.tsx': ['ts-node/register', 'typescript-node/register'],
114   '.wisp': 'wisp/engine/node',
115   '.xml': 'require-xml',
116   '.yaml': 'require-yaml',
117   '.yml': 'require-yaml'
118 };
119 ```
120
121 ### jsVariants
122 Same as above, but only include the extensions which are javascript variants.
123
124 ## How to use it
125
126 Consumers 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:
127
128 1. If the value is null, do nothing.
129
130 2. If the value is a string, try to require it.
131
132 3. 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.
133
134 4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
135
136 [require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions