Socket
Socket
Sign inDemoInstall

interpret

Package Overview
Dependencies
0
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    interpret

A dictionary of file extensions and associated module loaders.


Version published
Weekly downloads
19M
decreased by-1.61%
Maintainers
2
Install size
12.4 kB
Created
Weekly downloads
 

Package description

What is interpret?

The interpret npm package is designed to be a dictionary of require extensions and associated file extensions. It allows developers to automatically register the appropriate require extension for files based on their file extensions. This is particularly useful when working with different types of files that need to be required in Node.js applications, such as .coffee, .ts, or .jsx files.

What are interpret's main functionalities?

Registering require extensions

This code retrieves the require extension for TypeScript files, allowing Node.js to understand how to process and import .ts files.

require('interpret').extensions['.ts']

Associating file extensions with custom handlers

This code demonstrates how to associate a custom file extension (.custom) with a custom compiler or handler to be used when requiring files with that extension.

var interpret = require('interpret');
var extensions = interpret.extensions;
extensions['.custom'] = require('my-custom-compiler');

Other packages similar to interpret

Readme

Source

interpret

A dictionary of file extensions and associated module loaders.

NPM

What is it

This is used by Liftoff to automatically require dependencies for configuration files, and by rechoir for registering module loaders.

API

extensions

Map file types to modules which provide a require.extensions loader.

{
  '.babel.js': [
    {
      module: '@babel/register',
      register: function (module) {
        module({
          // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
          // which only captures the final extension (.babel.js -> .js)
          extensions: '.js'
        });
      }
    },
    {
      module: 'babel-register',
      register: function (module) {
        module({
          // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
          // which only captures the final extension (.babel.js -> .js)
          extensions: '.js'
        });
      }
    },
    {
      module: 'babel-core/register',
      register: function (module) {
        module({
          extensions: '.js'
        });
      }
    },
    {
      module: 'babel/register',
      register: function (module) {
        module({
          extensions: '.js'
        });
      }
    }
  ],
  '.buble.js': 'buble/register',
  '.cirru': 'cirru-script/lib/register',
  '.cjsx': 'node-cjsx/register',
  '.co': 'coco',
  '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  '.csv': 'require-csv',
  '.eg': 'earlgrey/register',
  '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
  '.iced.md': 'iced-coffee-script/register',
  '.ini': 'require-ini',
  '.js': null,
  '.json': null,
  '.json5': 'json5/lib/require',
  '.jsx': [
    {
      module: '@babel/register',
      register: function (module) {
        module({
          extensions: '.jsx'
        });
      }
    },
    {
      module: 'babel-register',
      register: function (module) {
        module({
          extensions: '.jsx'
        });
      }
    },
    {
      module: 'babel-core/register',
      register: function (module) {
        module({
          extensions: '.jsx'
        });
      }
    },
    {
      module: 'babel/register',
      register: function (module) {
        module({
          extensions: '.jsx'
        });
      },
    },
    {
      module: 'node-jsx',
      register: function (module) {
        module.install({
          extension: '.jsx',
          harmony: true
        });
      }
    }
  ],
  '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  '.liticed': 'iced-coffee-script/register',
  '.ls': ['livescript', 'LiveScript'],
  '.node': null,
  '.toml': {
    module: 'toml-require',
    register: function (module) {
      module.install();
    }
  },
  '.ts': ['ts-node/register', 'typescript-node/register', 'typescript-register', 'typescript-require'],
  '.tsx': ['ts-node/register', 'typescript-node/register'],
  '.wisp': 'wisp/engine/node',
  '.xml': 'require-xml',
  '.yaml': 'require-yaml',
  '.yml': 'require-yaml'
};

jsVariants

Same as above, but only include the extensions which are javascript variants.

How to use it

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:

  1. If the value is null, do nothing.

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

  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.

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

Keywords

FAQs

Last updated on 27 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc