版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. # interpret
  7. [![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]
  8. A dictionary of file extensions and associated module loaders.
  9. ## What is it
  10. 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.
  11. ## interpret for enterprise
  12. Available as part of the Tidelift Subscription
  13. The maintainers of interpret and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-interpret?utm_source=npm-interpret&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
  14. ## API
  15. ### extensions
  16. Map file types to modules which provide a [require.extensions] loader.
  17. ```js
  18. {
  19. '.babel.js': [
  20. {
  21. module: '@babel/register',
  22. register: function(hook) {
  23. hook({
  24. extensions: '.js',
  25. rootMode: 'upward-optional',
  26. ignore: [ignoreNonBabelAndNodeModules],
  27. });
  28. },
  29. },
  30. {
  31. module: 'babel-register',
  32. register: function(hook) {
  33. hook({
  34. extensions: '.js',
  35. ignore: ignoreNonBabelAndNodeModules,
  36. });
  37. },
  38. },
  39. {
  40. module: 'babel-core/register',
  41. register: function(hook) {
  42. hook({
  43. extensions: '.js',
  44. ignore: ignoreNonBabelAndNodeModules,
  45. });
  46. },
  47. },
  48. {
  49. module: 'babel/register',
  50. register: function(hook) {
  51. hook({
  52. extensions: '.js',
  53. ignore: ignoreNonBabelAndNodeModules,
  54. });
  55. },
  56. },
  57. ],
  58. '.babel.ts': [
  59. {
  60. module: '@babel/register',
  61. register: function(hook) {
  62. hook({
  63. extensions: '.ts',
  64. rootMode: 'upward-optional',
  65. ignore: [ignoreNonBabelAndNodeModules],
  66. });
  67. },
  68. },
  69. ],
  70. '.buble.js': 'buble/register',
  71. '.cirru': 'cirru-script/lib/register',
  72. '.cjsx': 'node-cjsx/register',
  73. '.co': 'coco',
  74. '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  75. '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  76. '.csv': 'require-csv',
  77. '.eg': 'earlgrey/register',
  78. '.esm.js': {
  79. module: 'esm',
  80. register: function(hook) {
  81. // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
  82. // which only captures the final extension (.babel.js -> .js)
  83. var esmLoader = hook(module);
  84. require.extensions['.js'] = esmLoader('module')._extensions['.js'];
  85. },
  86. },
  87. '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
  88. '.iced.md': 'iced-coffee-script/register',
  89. '.ini': 'require-ini',
  90. '.js': null,
  91. '.json': null,
  92. '.json5': ['json5/lib/register', 'json5/lib/require'],
  93. '.jsx': [
  94. {
  95. module: '@babel/register',
  96. register: function(hook) {
  97. hook({
  98. extensions: '.jsx',
  99. rootMode: 'upward-optional',
  100. ignore: [ignoreNonBabelAndNodeModules],
  101. });
  102. },
  103. },
  104. {
  105. module: 'babel-register',
  106. register: function(hook) {
  107. hook({
  108. extensions: '.jsx',
  109. ignore: ignoreNonBabelAndNodeModules,
  110. });
  111. },
  112. },
  113. {
  114. module: 'babel-core/register',
  115. register: function(hook) {
  116. hook({
  117. extensions: '.jsx',
  118. ignore: ignoreNonBabelAndNodeModules,
  119. });
  120. },
  121. },
  122. {
  123. module: 'babel/register',
  124. register: function(hook) {
  125. hook({
  126. extensions: '.jsx',
  127. ignore: ignoreNonBabelAndNodeModules,
  128. });
  129. },
  130. },
  131. {
  132. module: 'node-jsx',
  133. register: function(hook) {
  134. hook.install({ extension: '.jsx', harmony: true });
  135. },
  136. },
  137. ],
  138. '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  139. '.liticed': 'iced-coffee-script/register',
  140. '.ls': ['livescript', 'LiveScript'],
  141. '.mjs': '/absolute/path/to/interpret/mjs-stub.js',
  142. '.node': null,
  143. '.toml': {
  144. module: 'toml-require',
  145. register: function(hook) {
  146. hook.install();
  147. },
  148. },
  149. '.ts': [
  150. 'ts-node/register',
  151. 'typescript-node/register',
  152. 'typescript-register',
  153. 'typescript-require',
  154. 'sucrase/register/ts',
  155. {
  156. module: '@babel/register',
  157. register: function(hook) {
  158. hook({
  159. extensions: '.ts',
  160. rootMode: 'upward-optional',
  161. ignore: [ignoreNonBabelAndNodeModules],
  162. });
  163. },
  164. },
  165. ],
  166. '.tsx': [
  167. 'ts-node/register',
  168. 'typescript-node/register',
  169. 'sucrase/register',
  170. {
  171. module: '@babel/register',
  172. register: function(hook) {
  173. hook({
  174. extensions: '.tsx',
  175. rootMode: 'upward-optional',
  176. ignore: [ignoreNonBabelAndNodeModules],
  177. });
  178. },
  179. },
  180. ],
  181. '.wisp': 'wisp/engine/node',
  182. '.xml': 'require-xml',
  183. '.yaml': 'require-yaml',
  184. '.yml': 'require-yaml',
  185. }
  186. ```
  187. ### jsVariants
  188. Same as above, but only include the extensions which are javascript variants.
  189. ## How to use it
  190. 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:
  191. 1. If the value is null, do nothing.
  192. 2. If the value is a string, try to require it.
  193. 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.
  194. 4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
  195. [require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
  196. [downloads-image]: http://img.shields.io/npm/dm/interpret.svg
  197. [npm-url]: https://www.npmjs.com/package/interpret
  198. [npm-image]: http://img.shields.io/npm/v/interpret.svg
  199. [travis-url]: https://travis-ci.org/gulpjs/interpret
  200. [travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci
  201. [appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret
  202. [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor
  203. [coveralls-url]: https://coveralls.io/r/gulpjs/interpret
  204. [coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg
  205. [gitter-url]: https://gitter.im/gulpjs/gulp
  206. [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg