module-interop
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Get underlying CommonJS/ES6 module with require()

Simple function to determine whether a require()'d object is an ES6 module, and return its .default implementation if so.

Written in Typescript.

How to use

Simply wrap any call to require to get the underlying module:

meaningOfLife.ts

const meaningOfLife = 42;
 
export default meaningOfLife;
import moduleInterop from "module-interop";
 
// Doesn't matter if `require` uses `module.exports` or ES6 exports
const meaningOfLife = moduleInterop(require("./meaningOfLife.ts")); // 42

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i module-interop

Weekly Downloads

4

Version

1.2.0

License

MIT

Unpacked Size

3.48 kB

Total Files

7

Last publish

Collaborators

  • leebenson