UNPKG

2.91 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 '.eg': 'earlgrey/register',
33 '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
34 '.iced.md': 'iced-coffee-script/register',
35 '.ini': 'require-ini',
36 '.js': null,
37 '.json': null,
38 '.json5': 'json5/lib/require',
39 '.jsx': [
40 {
41 module: 'babel/register',
42 register: function (module) {
43 module({
44 extensions: '.jsx'
45 });
46 },
47 },
48 {
49 module: 'node-jsx',
50 register: function (module) {
51 module.install({
52 extension: '.jsx',
53 harmony: true
54 });
55 }
56 }
57 ],
58 '.litcoffee': ['coffee-script/register', 'coffee-script'],
59 '.liticed': 'iced-coffee-script/register',
60 '.ls': ['livescript', 'LiveScript'],
61 '.node': null,
62 '.toml': {
63 module: 'toml-require',
64 register: function (module) {
65 module.install();
66 }
67 },
68 '.ts': ['typescript-node/register', 'typescript-register', 'typescript-require'],
69 '.tsx': ['typescript-node/register'],
70 '.wisp': 'wisp/engine/node',
71 '.xml': 'require-xml',
72 '.yaml': 'require-yaml',
73 '.yml': 'require-yaml'
74};
75```
76
77### jsVariants
78Same as above, but only include the extensions which are javascript variants.
79
80## How to use it
81
82Consumers 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:
83
841. If the value is null, do nothing.
85
862. If the value is a string, try to require it.
87
883. 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.
89
904. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
91
92[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions