项目原始demo,不改动
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

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