Projekt

Obecné

Profil

Stáhnout (5.55 KB) Statistiky
| Větev: | Revize:
1
<p align="center">
2
  <a href="http://gulpjs.com">
3
    <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
4
  </a>
5
</p>
6

    
7
# interpret
8

    
9
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
10

    
11
A dictionary of file extensions and associated module loaders.
12

    
13
## What is it
14
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.
15

    
16
## API
17

    
18
### extensions
19
Map file types to modules which provide a [require.extensions] loader.
20

    
21
```js
22
{
23
  '.babel.js': [
24
    {
25
      module: '@babel/register',
26
      register: function(hook) {
27
        // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
28
        // which only captures the final extension (.babel.js -> .js)
29
        hook({ extensions: '.js' });
30
      },
31
    },
32
    {
33
      module: 'babel-register',
34
      register: function(hook) {
35
        hook({ extensions: '.js' });
36
      },
37
    },
38
    {
39
      module: 'babel-core/register',
40
      register: function(hook) {
41
        hook({ extensions: '.js' });
42
      },
43
    },
44
    {
45
      module: 'babel/register',
46
      register: function(hook) {
47
        hook({ extensions: '.js' });
48
      },
49
    },
50
  ],
51
  '.babel.ts': [
52
    {
53
      module: '@babel/register',
54
      register: function(hook) {
55
        hook({ extensions: '.ts' });
56
      },
57
    },
58
  ],
59
  '.buble.js': 'buble/register',
60
  '.cirru': 'cirru-script/lib/register',
61
  '.cjsx': 'node-cjsx/register',
62
  '.co': 'coco',
63
  '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
64
  '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
65
  '.csv': 'require-csv',
66
  '.eg': 'earlgrey/register',
67
  '.esm.js': {
68
    module: 'esm',
69
    register: function(hook) {
70
      // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
71
      // which only captures the final extension (.babel.js -> .js)
72
      var esmLoader = hook(module);
73
      require.extensions['.js'] = esmLoader('module')._extensions['.js'];
74
    },
75
  },
76
  '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
77
  '.iced.md': 'iced-coffee-script/register',
78
  '.ini': 'require-ini',
79
  '.js': null,
80
  '.json': null,
81
  '.json5': 'json5/lib/require',
82
  '.jsx': [
83
    {
84
      module: '@babel/register',
85
      register: function(hook) {
86
        hook({ extensions: '.jsx' });
87
      },
88
    },
89
    {
90
      module: 'babel-register',
91
      register: function(hook) {
92
        hook({ extensions: '.jsx' });
93
      },
94
    },
95
    {
96
      module: 'babel-core/register',
97
      register: function(hook) {
98
        hook({ extensions: '.jsx' });
99
      },
100
    },
101
    {
102
      module: 'babel/register',
103
      register: function(hook) {
104
        hook({ extensions: '.jsx' });
105
      },
106
    },
107
    {
108
      module: 'node-jsx',
109
      register: function(hook) {
110
        hook.install({ extension: '.jsx', harmony: true });
111
      },
112
    },
113
  ],
114
  '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
115
  '.liticed': 'iced-coffee-script/register',
116
  '.ls': ['livescript', 'LiveScript'],
117
  '.node': null,
118
  '.toml': {
119
    module: 'toml-require',
120
    register: function(hook) {
121
      hook.install();
122
    },
123
  },
124
  '.ts': [
125
    'ts-node/register',
126
    'typescript-node/register',
127
    'typescript-register',
128
    'typescript-require',
129
    {
130
      module: '@babel/register',
131
      register: function(hook) {
132
        hook({ extensions: '.ts' });
133
      },
134
    },
135
  ],
136
  '.tsx': [
137
    'ts-node/register',
138
    'typescript-node/register',
139
    {
140
      module: '@babel/register',
141
      register: function(hook) {
142
        hook({ extensions: '.tsx' });
143
      },
144
    },
145
  ],
146
  '.wisp': 'wisp/engine/node',
147
  '.xml': 'require-xml',
148
  '.yaml': 'require-yaml',
149
  '.yml': 'require-yaml',
150
}
151
```
152

    
153
### jsVariants
154
Same as above, but only include the extensions which are javascript variants.
155

    
156
## How to use it
157

    
158
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:
159

    
160
1. If the value is null, do nothing.
161

    
162
2. If the value is a string, try to require it.
163

    
164
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.
165

    
166
4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
167

    
168
[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
169

    
170
[downloads-image]: http://img.shields.io/npm/dm/interpret.svg
171
[npm-url]: https://www.npmjs.com/package/interpret
172
[npm-image]: http://img.shields.io/npm/v/interpret.svg
173

    
174
[travis-url]: https://travis-ci.org/gulpjs/interpret
175
[travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci
176

    
177
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret
178
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor
179

    
180
[coveralls-url]: https://coveralls.io/r/gulpjs/interpret
181
[coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg
182

    
183
[gitter-url]: https://gitter.im/gulpjs/gulp
184
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
(3-3/5)