Socket
Socket
Sign inDemoInstall

interpret

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interpret - npm Package Compare versions

Comparing version 0.3.8 to 0.3.9

4

index.js

@@ -8,2 +8,3 @@ var extensions = {

'.iced': 'iced-coffee-script/register',
'.iced.md': 'iced-coffee-script/register',
'.ini': 'require-ini',

@@ -14,2 +15,3 @@ '.js': null,

'.litcoffee': 'coffee-script/register',
'.liticed': 'iced-coffee-script/register',
'.ls': 'LiveScript',

@@ -39,4 +41,6 @@ '.toml': 'toml-require',

'.iced',
'.iced.md',
'.jsx',
'.litcoffee',
'.liticed',
'.ls',

@@ -43,0 +47,0 @@ '.ts'

2

package.json
{
"name": "interpret",
"description": "A dictionary of file extensions and associated module loaders.",
"version": "0.3.8",
"version": "0.3.9",
"homepage": "https://github.com/tkellen/node-interpret",

@@ -6,0 +6,0 @@ "author": {

@@ -21,2 +21,3 @@ # interpret

'.iced': 'iced-coffee-script/register',
'.iced.md': 'iced-coffee-script/register',
'.ini': 'require-ini',

@@ -27,2 +28,3 @@ '.js': null,

'.litcoffee': 'coffee-script/register',
'.liticed': 'iced-coffee-script/register',
'.ls': 'livescript',

@@ -58,4 +60,6 @@ '.toml': 'toml-require',

'.iced': 'iced-coffee-script/register',
'.iced.md': 'iced-coffee-script/register',
'.jsx': 'node-jsx',
'.litcoffee': 'coffee-script/register',
'.liticed': 'iced-coffee-script/register',
'.ls': 'livescript',

@@ -67,1 +71,41 @@ '.ts': 'typescript-require'

[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
### Example Usage
```js
const interpret = require('interpret');
const path = require('path');
const resolve = require('resolve');
// register support for a defined extension
function register(filepath, cwd) {
// find the extension of the requested filename
var ext = path.extname(filepath);
// see if this extension is already supported
if (Object.keys(require.extensions).indexOf(ext) !== -1) {
return;
}
// if no cwd is specified, assume we want to use the
// directory the requested file exists in
if (!cwd) {
cwd = path.dirname(path.resolve(filepath));
}
// find out which module is needed to read this extension
var moduleName = interpret.extensions[ext];
// if a module exists for this extension, make it usable
if (moduleName) {
// find the module relative to cwd that can add support for this extension
var module = resolve.sync(moduleName, {basedir: cwd})
// require it
var compiler = require(module);
// see if there is a method needed beyond requiring to enable support
var register = interpret.register[moduleName];
// if there is, run it
if (register) {
register(compiler);
}
}
}
```
Note: this is more or less exactly how [rechoir](http://github.com/tkellen/node-rechoir) works.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc